You need to sign in to do that
Don't have an account?
Update date field in salesforce using javascript custom button
hi there,
I need to update the date Data type field in salesforce using javascript code.
{!REQUIRESCRIPT("/soap/ajax/39.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/39.0/apex.js")}
sforce.connection.sessionId = "{!$Api.Session_ID}";
var record = new sforce.SObject("Account");
var currentDate = new Date();
var date = currentDate.getDate();
var month = currentDate.getMonth();
var year = currentDate.getFullYear();
var monthDateYear = (month+1) + "/" + date + "/" + year;
record.Membership_Change_Dates__c = new Date(monthDateYear);
sforce.connection.update([record]);
It returns DateTime, not date.
please assist!
Thanks
LN
I need to update the date Data type field in salesforce using javascript code.
{!REQUIRESCRIPT("/soap/ajax/39.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/39.0/apex.js")}
sforce.connection.sessionId = "{!$Api.Session_ID}";
var record = new sforce.SObject("Account");
var currentDate = new Date();
var date = currentDate.getDate();
var month = currentDate.getMonth();
var year = currentDate.getFullYear();
var monthDateYear = (month+1) + "/" + date + "/" + year;
record.Membership_Change_Dates__c = new Date(monthDateYear);
sforce.connection.update([record]);
It returns DateTime, not date.
please assist!
Thanks
LN
Mon Aug 05 2019 12:47:18 GMT+0530 (India Standard Time)
https://www.w3schools.com/js/js_dates.asp
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date#Methods
P.S.: The above code is working fine in my org for updating the date field.
All Answers
Greetings to you!
You just need to add below line of code:
record.id ="{!Account.Id}";
Try below code:
Or you can use the below code:
I hope it helps you.
Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.
Thanks and Regards,
Khan Anas
Khan Anas
I tried this but it always returns me date time
Thanks
LN
Mon Aug 05 2019 12:47:18 GMT+0530 (India Standard Time)
https://www.w3schools.com/js/js_dates.asp
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date#Methods
P.S.: The above code is working fine in my org for updating the date field.