You need to sign in to do that
Don't have an account?
javascript List to check if a field on all selected records is the same
Hi,
I have a javascript list button "Create Purchase order" on custom object Order_Lines__c(child object of Sales_Order__c) which creates a purchase order for the selected order lines.
The code goes like this :
{!REQUIRESCRIPT("/soap/ajax/13.0/connection.js")}
var records = {!GETRECORDIDS($ObjectType.Order_Line__c)};
var newRecords = [];
/*Ensure atleast one order line is selected*/
if (records[0] == null)
{
alert("Please select at least one Order Line")
}
/*Create a purchase order for the selected records*/
else
{
for (var n=0; n<records.length; n++) {
var c = new sforce.SObject("Order_line__c");
c.id = records[n];
newRecords.push(c);
}
result = sforce.connection.update(newRecords);
/*Open a new Purchase Order form and prepopulate with values*/
window.location.href ="/a0I/e?retURL=%2Fa0I%2Fo"+
"&CF00NR0000000cvG6={!Sales_Order__c.Name}"+
"&CF00NR0000000cvEt={!Sales_Order__c.Default_Warehouse__c}" +
"&00NR0000000cvEU={!Sales_Order__c.Order_Date__c}
}
This is working fine.
Now i want to add another validation:The field supplier__c on the order lines object must have the same value for the selected records.
I have tried adding the validation as follows:
{!REQUIRESCRIPT("/soap/ajax/13.0/connection.js")}
var records = {!GETRECORDIDS($ObjectType.Order_Line__c)};
var newRecords = [];
/*Check if records are selected*/
if (records[0] == null)
{
alert("Please select at least one Order Line");
}
else{
var myarray=new Array();
for (var n=0; n<records.length; n++) {
var c = new sforce.SObject("Order_line__c");
c.id = records[n];
/*Copy the supplier field into an array for all the selected order lines*/
myarray[n]=c.supplier__c;
} }
var t=array.length-1;
for (var d=0;d<t;d++)
{
if(array[d] <>array[d+1]){
alert("SOrry ,need same supplier for each order line");
}
else
{
/*Code for creating a new Purchase order*/
}
}
however this is not working and it gives a syntax error.
Please help with the syntax and the logic used if its not ok.
Since I don't know the specifics of your error, the only thing that jumps out at me is that you have a typo in your reference to the array you're using to store the suppliers. You declare the array as "myarray", but you are referencing it as "array". Straighten that out and see if it helps.