+ Start a Discussion
neshnesh 

When i click list view button-up[date customfield-Using onclick javascript

When i click list view  button -selected records custom field are updated in corresponding records..Usong onclick javascript

My code :

{!REQUIRESCRIPT("/soap/ajax/19.0/connection.js")} //adds the proper code for inclusion of AJAX toolkit 
var url = parent.location.href; //string for the URL of the current page 
var records = {!GETRECORDIDS($ObjectType.Training__c)}; //grabs the Lead records that the user is requesting to update 
var updateRecords = []; //array for holding records that this code will ultimately update 

if (records[0] == null) {  

//if the button was clicked but there was no record selected 
alert

("Please select at least one record to update."); //alert the user that they didn't make a selection 
} else { //otherwise, there was a record selection 
for (var a=0; a<records.length; a++) { //for all records 
var update_Train = new sforce.SObject("Training__c"); //create a new sObject for storing updated record details 
update_Train.Id = records[a]; //set the Id of the selected Lead record 
update_Train.Training_Status__c= 'Pass'; or  update_Train.Status__c = true;
updateRecords.push(update_Train); 

result = sforce.connection.update(updateRecords); 
parent.location.href = url; //refresh the page 
}

Above code doesnt update record .When i click Please give ur idea when click  list button update or insert  the custom field - please help me.

Puja_mfsiPuja_mfsi

Hello,

Please take a reference from the below code.It's working code:

 

 

{!REQUIRESCRIPT("/soap/ajax/29.0/connection.js")} 
var url = parent.location.href; 
var records = {!GETRECORDIDS($ObjectType.Account)}; 
var updateRecords = []; 
if (records[0] == null) { 
alert("Please select at least one record to update."); 
} else { 
for (var a=0; a<records.length; a++) { 
var caseObj = new sforce.SObject("Case"); 
caseObj.Id = records[a]; 
caseObj.Origin = 'Web'; 

caseObj.Product__c = 'GC1040'; 
updateRecords.push(caseObj); 


result = sforce.connection.update(updateRecords); 
parent.location.href = url; 
}

 

Please let me know if u have any problem on same and if this post help u please throw KUDOS by click on star at left.