+ Start a Discussion
satyamsatyam 

Urgent Need help with custom button javascript

Hi,

 

I am using custom button to select the record for some operation but i am getting below error:

 

A problem with the OnClick JavaScript for this button or link was encountered:

{faultcode:'soapenv:Client', faultstring:'A duplicate value was specified for field 'Ids__c' in object 'Student_Support_Ids__c', duplicate value 'a50E00000008Oxs' prior value 'a50E00000008Oxr'', }

 

Can anyone please help me out .

 

Below is my code:

 

{!REQUIRESCRIPT("/soap/ajax/19.0/connection.js")};


var records={!GETRECORDIDS($ObjectType.student_Support__c )};

if(records[0]==null) {

alert("Please select atleast one record.");

} else {
var flag = false;


var psrecords=sforce.connection.retrieve("Id,Status__c,SAP_Transfer__c,Support_Type__c,Archieved__c","student_Support__c", [records])



for(var i=0; i<psrecords.length; i++){

var recordId =psrecords [i];
var Arch=recordId.Archieved__c;
if(Arch=='true')
{
flag = true;
alert("You Can not do Mass change for Archived student support!!");
break;
}else if(recordId.Status__c != 'Approved' &&Arch!='true'){
flag = true;
alert("Mass Change can be done only for Approved student Supports");
break;

}else if(recordId.Support_Type__c=='Rebate' && recordId.Status__c == 'Approved' && recordId.SAP_Transfer__c=='Open' &&Arch!='true'){
flag = true;
alert('Support # '+recordId.Support_ID__c+' is currently being transferred, therefore you cannot do a Mass Change now.');
break;
}
}
}

if( flag == false){
var insert_PSIDs = new sforce.SObject("student_Support_Ids__c");
alert(records);
insert_PSIDs.Ids__c = records;
var result = sforce.connection.create([insert_PSIDs]);
alert(result);
window.open("/apex/studentSupportMassChange?selectedRecords="+result[0].id);
}

 

Thanks in Advance :))))

Puja_mfsiPuja_mfsi

Hi,

Use the below code  instead of "insert_PSIDs.Ids__c = records;"

 

var ids = ""; 
for( var i=0; i<records.length;i++ ){ 
  ids += records[i] +','; 

 insert_PSIDs.Ids__c = ids;