You need to sign in to do that
Don't have an account?
Matt Cooper 7
Custom button not updating field values.
Hi,
I have created a custom button with the intent that it be used to update a field value. I have built buttons like this before that have worked successfully, but for some reason this button is not updating any field values. The alert I setup works, and the page reloads as the code tells it to do. The only thing that doesn't occur is the field value updating. Can anyone please help me figure out what is going wrong?
Here are two versions of the code that I built:
VERSION 1:
{!REQUIRESCRIPT("/soap/ajax/19.0/connection.js")}
{
var agmt = new sforce.SObject("Apttus__APTS_Agreement__c");
var agmtId = "{!Apttus__APTS_Agreement__c.Id}";
var status = "Submitted Request";
agmt.Id = agmtId;
if('{!Apttus__APTS_Agreement__c.Apttus__Status__c}' != 'Request'){
alert('This agreement has already been sent to Tax.');
}
else{
agmt.Apttus__Status__c = status;
result = sforce.connection.update([agmt]);
window.location.reload();
}}
VERSION 2:
{!REQUIRESCRIPT("/soap/ajax/19.0/connection.js")}
var agmt = new sforce.SObject("Apttus__APTS_Agreement__c");
agmt.Id = '{!Apttus__APTS_Agreement__c.Id}';
if(agmt.Apttus__Status__c != 'Request'){
alert('This agreement has already been sent to Tax.');
}
else{
agmt.Apttus__Status__c = 'Submitted Request';
result = sforce.connection.update([agmt]);
window.location.reload();
}
Thanks!
I have created a custom button with the intent that it be used to update a field value. I have built buttons like this before that have worked successfully, but for some reason this button is not updating any field values. The alert I setup works, and the page reloads as the code tells it to do. The only thing that doesn't occur is the field value updating. Can anyone please help me figure out what is going wrong?
Here are two versions of the code that I built:
VERSION 1:
{!REQUIRESCRIPT("/soap/ajax/19.0/connection.js")}
{
var agmt = new sforce.SObject("Apttus__APTS_Agreement__c");
var agmtId = "{!Apttus__APTS_Agreement__c.Id}";
var status = "Submitted Request";
agmt.Id = agmtId;
if('{!Apttus__APTS_Agreement__c.Apttus__Status__c}' != 'Request'){
alert('This agreement has already been sent to Tax.');
}
else{
agmt.Apttus__Status__c = status;
result = sforce.connection.update([agmt]);
window.location.reload();
}}
VERSION 2:
{!REQUIRESCRIPT("/soap/ajax/19.0/connection.js")}
var agmt = new sforce.SObject("Apttus__APTS_Agreement__c");
agmt.Id = '{!Apttus__APTS_Agreement__c.Id}';
if(agmt.Apttus__Status__c != 'Request'){
alert('This agreement has already been sent to Tax.');
}
else{
agmt.Apttus__Status__c = 'Submitted Request';
result = sforce.connection.update([agmt]);
window.location.reload();
}
Thanks!
result = sforce.connection.update([agmt]);
if (result[0].getBoolean("success")) {
alert("account with id " + result[0].id + " updated");
} else {
alert("failed to update account " + result[0]);
}
All Answers
as it's like a refrence field so it should be like Apttus__APTS_Agreement__r.Apttus__Status__c and please make sure you are using proper case in field Api name with the Nampespace as javascript is case sensitive.
Hope it will help you
result = sforce.connection.update([agmt]);
if (result[0].getBoolean("success")) {
alert("account with id " + result[0].id + " updated");
} else {
alert("failed to update account " + result[0]);
}