Updating field using Javascript using a custom button

1. Create a button with label 'Add Employee'.

2. Select '

3. Select 'Execute JavaScript' as a behaviour.

4. Add the below code

{!REQUIRESCRIPT("/soap/ajax/20.0/connection.js")}

var newRecords = [];

var a = new sforce.SObject("Account");

a.id ="{!Account.Id}";
a.NumberOfEmployees = {!Account.NumberOfEmployees} + 1;
newRecords.push(a);

result = sforce.connection.update(newRecords);

window.location.reload();


5. Click 'Save' button.

6. Add the button to the page layout.




It will increment the Employees.

No comments:

Post a Comment