You need to sign in to do that
Don't have an account?
Custom OnClick JavaScript Button to Update Date Field
I'm trying to create a custom OnClick JavaScript button that will update a date field on an Opportunity when clicked with today's date.
Here is the code I'm using:
{!REQUIRESCRIPT("/soap/ajax/20.0/connection.js")}
var newRecords = [];
var c = new sforce.SObject("Opportunity");
c.id ="{!Opportunity.Id}";
c.{!Opportunity.Media_Plan_Approved__c} = new Date();
newRecords.push(c);
result = sforce.connection.update(newRecords);
window.location.reload();
When I test the button though, I get a message in a pop up window that says:
"A problem with the OnClick JavaScript button or link was encountered:
Expected Identifier"
I really don't know Java that well. Can anyone tell me what I'm doing wrong?
Thanks!!
Hey,
Nearly there, just one lil tweak
c.{!Opportunity.Media_Plan_Approved__c} = new Date();
should read
c.Media_Plan_Approved__c = new Date();
All Answers
Hey,
Nearly there, just one lil tweak
c.{!Opportunity.Media_Plan_Approved__c} = new Date();
should read
c.Media_Plan_Approved__c = new Date();
That was almost too easy :) Thanks so much!! Worked beautifully!!!
Sweet. All's well that ends well :)
Hello,
Am having the same issue. I can update a text field but not a field of type checkbox.
Has anyone been able to update a checkbox field?Is my syntax wrong?
{!requireScript("/soap/ajax/22.0/connection.js")}
{!requireScript("/soap/ajax/22.0/apex.js")}
var callArray = new Array();
var c= new sforce.SObject("Call__c");
c.Initialize__c = true;//field type checkbox
c.CallObjectives__c = "test";
c.set("Id","{!Call__c.Id}");
callArray .push(c);
try
{
// update the Group of Records
var responseUpdate = sforce.connection.update(callArray);
}
catch (error)
{
alert("Failed to Update with error: " + error);
}
Thanks
Siim