function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Sandy GaliSandy Gali 

custom button not working - sforce.connection.update

Hi Guys,
            I wrote a piece of code which checks few condtions and updates a field in the end but the update is not working.

Below is the code. It goes in to the else block but DevIncidientSubmit__c  is not getting updated.
Any help in this regards is appreciated.


{!REQUIRESCRIPT("/soap/ajax/29.0/connection.js")} 
{!requireScript("/soap/ajax/29.0/apex.js")} 
var SQLu = "Select Id,Drive_Guest_Count__c,Travel_Sector_Count__c,Status__c,DevIncidientSubmit__c from Application__c where id='{!Application__c.Id}'"; 
var flag = false; 
var application = new sforce.SObject("Application__c"); 
result = sforce.connection.query(SQLu); 
records = result.getArray("records"); 
for(i=0; i < result.getArray("records").length; i++) 

if (result.getArray("records")[i].Travel_Sector_Count__c <= 0.0 && result.getArray("records")[i].Drive_Guest_Count__c == "true") 

alert("Please enter at least one travel sector and one drive guest application"); 

else if(result.getArray("records")[i].Drive_Guest_Count__c == "true" ) 

alert("Please enter at least one drive guest application application"); 

else if (result.getArray("records")[i].Travel_Sector_Count__c <= 0.0) 

alert("Please enter at least one travel sector application"); 

else 

alert("In final else"); 
result.getArray("records")[i].DevIncidientSubmit__c = "True"; 




sforce.connection.update(result.getArray("records")); 
alert("The value of getarray is"+result.getArray("records")); 
location.reload();