You need to sign in to do that
Don't have an account?
Sean Napier
Button on Custom Object to edit field on Opportunity
Hi all,
I'm a bit new to this so I apologize if this is not even possible.
I created a Button on a custom Object I have with the intention of having a checkbox on the related Opportunity updated when the button is clicked. This is what I have:
{!REQUIRESCRIPT("/soap/ajax/29.0/connection.js")}
// identify the record
var o = new sforce.SObject("Opportunity");
o.id = "{!Medical_Consult__c.Patient__c}"; // Medical_Consult__c is my custom Object name Patient__c is the Opportunity lookup
// make the field change
o.Consult_Document_Fully_Completed__c = true; //This is the field on the Opportunity
// save the change
sforce.connection.update([o]);
//refresh the page
window.location.reload();
I'm not getting any errors when I click this button but the field is not updated on the Opportunity.
Any help would be greatly appreciated.
I'm a bit new to this so I apologize if this is not even possible.
I created a Button on a custom Object I have with the intention of having a checkbox on the related Opportunity updated when the button is clicked. This is what I have:
{!REQUIRESCRIPT("/soap/ajax/29.0/connection.js")}
// identify the record
var o = new sforce.SObject("Opportunity");
o.id = "{!Medical_Consult__c.Patient__c}"; // Medical_Consult__c is my custom Object name Patient__c is the Opportunity lookup
// make the field change
o.Consult_Document_Fully_Completed__c = true; //This is the field on the Opportunity
// save the change
sforce.connection.update([o]);
//refresh the page
window.location.reload();
I'm not getting any errors when I click this button but the field is not updated on the Opportunity.
Any help would be greatly appreciated.
try like this,
Let us know if it helps,
Thanks,
Balayesu
I thought maybe I could create a custom field to hold the Opp ID after getting the above so I updated it to:
var strQuery="Select Id,Consult_Document_Fully_Completed__c from Opportunity where Id= '" +'{!Medical_Consult__c.OppID__c }'+"'";
After doing that I do not recieve the above error but nothing happens when I click the button.
Let us know if it helps.
{!REQUIRESCRIPT("/soap/ajax/23.0/connection.js")}
var __sfdcSessionId = '{!GETSESSIONID()}';
var result='';
try {
var strQuery="Select Id,Consult_Document_Fully_Completed__c from Opportunity where Name= '" +'{!Medical_Consult__c.Patient__c}'+"'";
var newRecords = [];
var otherP = sforce.connection.query(strQuery);
var records = otherP.getArray("records");
if (records.length >= 1) {
for(var i=0; i < records.length ; i ++) {
var ob = new sforce.SObject("Opportunity");
ob.Id = records[i].Id;
ob.Consult_Document_Fully_Completed__c = true;
result += sforce.connection.update([ob]);
}
alert("You have Successfully Locked the Consult");
location.reload(true);
}
}catch(er) {
alert(er);
}
Have an awesome day!