You need to sign in to do that
Don't have an account?
Kruvi
Error in Javascript for Custom button
Hello
This is my first attempt to write javascript for an action button.
I want to iterate through a list of Strings (generated by splitting a long comma separated string).
I want to process these Strings in batches equal to Quanta value.
Problem is that when I push the button I get this Error:
Unexpected token: ILLEGAL
This is my code:
{!requireScript("/soap/ajax/22.0/connection.js")} {!requireScript("/soap/ajax/22.0/apex.js")} sforce.debug.trace=true; var quota = {!$Setup.testtt__Gateway_Setting__c.testtt__Max_Quota__c}; var Id = '{!testtt__Micro_Campaign__c.Id}' var recipients = {!testtt__Micro_Campaign__c.testtt__Distribution_List__c}.split(','); var startSlice = 0; var endSlice = quota; var silices = 0; var timeout; function timedPublish(){ var result; while(silices < quota){ result = executePublish(recipients.slice(startSlice, endSlice)); if(result == 0){ alert(" Messages are being processed and published. This might take time depending on the number of recipients"); window.location.reload(); } else{ alert("Some error was found and publishing as stopped. please check the logs."); } startSlice = endSlice++; if(endSlice <= recipients.lenght) endSlice = i*quota; else endslice = recipients.lenght; slices++; timeout = setTimeout("timedPublish()",2000); } clearTimeout(timeout); } function executePublish(toNumbers){ return result = sforce.apex.execute( "testtt/MicroCampaignAPI", // class "publishCampaign", // method {campaignID: Id, recipients: toNumbers}); //arguments }
Any idea what am I doing wrong?
Many Thanks
Ensure your visualforce page...its may be incorrect script call...
Hello kruvi,
I think the problem may be due to recipients.lenght, Change it to recipients.length,
And also i is not defined here: endSlice = i*quota;
And Check the datatype of the variables wherever you are assigning or comparing the values.
Put alerts in places and find exact line number of error.