You need to sign in to do that
Don't have an account?
Andrew Aldis
A problem with the OnClick JavaScript for this button or link was encountered: records[i] is undefined
I have a custom button which is generate child records. The button works perfectly but before in creates the record I get the following error message. A problem with the OnClick JavaScript for this button or link was encountered: records[i] is undefined. I cannot get rid of that error message but other that that it works perfectly can someone let me know what I need to do to get rid of that error? My Code is below.
{!REQUIRESCRIPT("/soap/ajax/29.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/29.0/apex.js")}
var userId = '{!$User.Id}';
var utc = new Date().toJSON().slice(0,10);
var sol = "Select Id, PSA_Assigned_to_ID__c, PSA_BIllable_Hours__c, PSA_Duration__c,PSA_Task_Automation__c, PSA_Task_Automation_Notes__c, PSA_Task_Automation_Role__c, PSA_Task_Automation_Task_Name__c From SCMC__Sales_Order_Line_Item__c where PSA_Task_Automation__c = True AND PSA_Created__c = False AND SCMC__Sales_Order__r.Installation__c = '{!SFDC_Project__c.Id}'";
var query = sforce.connection.query(sol);
var records = query.getArray("records");
if(userId != "00580000008JMjO" )
{alert("Only authorized staff can auto create Project Tasks, if you need to auto-create Project Tasks contact bi@fourwindsinteractive.com to request access.")
}else{
confirm("There are "+records.length+" Sales Order Line Items that will auto-create Project Tasks. Click OK to create tasks.");
for(var i=0; i<=records.length; i++){
var psa = new sforce.SObject("Project_Task__c");
psa.Project__c = '{!SFDC_Project__c.Id}';
psa.Assigned_To__c = records[i].PSA_Assigned_to_ID__c;
psa.Project_Task_Notes__c = records[i].PSA_Task_Automation_Notes__c;
psa.Role__c = records[i].PSA_Task_Automation_Role__c;
psa.Task__c = records[i].PSA_Task_Automation_Task_Name__c;
psa.Start_Date__c = utc;
psa.Duration__c = records[i].PSA_Duration__c;
psa.Budgeted_Billable_Hours__c = records[i].PSA_BIllable_Hours__c;
console.log(psa);
result=sforce.connection.create([psa]);
console.log(result);
}
}
{!REQUIRESCRIPT("/soap/ajax/29.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/29.0/apex.js")}
var userId = '{!$User.Id}';
var utc = new Date().toJSON().slice(0,10);
var sol = "Select Id, PSA_Assigned_to_ID__c, PSA_BIllable_Hours__c, PSA_Duration__c,PSA_Task_Automation__c, PSA_Task_Automation_Notes__c, PSA_Task_Automation_Role__c, PSA_Task_Automation_Task_Name__c From SCMC__Sales_Order_Line_Item__c where PSA_Task_Automation__c = True AND PSA_Created__c = False AND SCMC__Sales_Order__r.Installation__c = '{!SFDC_Project__c.Id}'";
var query = sforce.connection.query(sol);
var records = query.getArray("records");
if(userId != "00580000008JMjO" )
{alert("Only authorized staff can auto create Project Tasks, if you need to auto-create Project Tasks contact bi@fourwindsinteractive.com to request access.")
}else{
confirm("There are "+records.length+" Sales Order Line Items that will auto-create Project Tasks. Click OK to create tasks.");
for(var i=0; i<=records.length; i++){
var psa = new sforce.SObject("Project_Task__c");
psa.Project__c = '{!SFDC_Project__c.Id}';
psa.Assigned_To__c = records[i].PSA_Assigned_to_ID__c;
psa.Project_Task_Notes__c = records[i].PSA_Task_Automation_Notes__c;
psa.Role__c = records[i].PSA_Task_Automation_Role__c;
psa.Task__c = records[i].PSA_Task_Automation_Task_Name__c;
psa.Start_Date__c = utc;
psa.Duration__c = records[i].PSA_Duration__c;
psa.Budgeted_Billable_Hours__c = records[i].PSA_BIllable_Hours__c;
console.log(psa);
result=sforce.connection.create([psa]);
console.log(result);
}
}
var ps = records[i];
and use ps in place of records[i]