function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
The_A-RodThe_A-Rod 

javascript button error

I am getting the following error when I try configuring a JavaScript button, which should create a Task record

User-added image


This is my script

{!REQUIRESCRIPT('/soap/ajax/30.0/connection.js')}
var connection = sforce.connection;
var newtask= new sforce.SObject("Task");
newtask.Subject = "Tried Calling";
newtask.WhoId="{!Lead.Id}";
newtask.Description="Tried calling, but could not get through";
newtask.ActivityDate={!Today}
newtask.Status="Completed";
newtask.Type="Admin Call";
newtask.Priority="Low";
result = sforce.connection.create([newtask]);
alert(result );

I am a total beignner at this, so have copied and amended this script based on other posts
Best Answer chosen by The_A-Rod
Abhishek BansalAbhishek Bansal
Hi,

Please update your code with the below code :
{!REQUIRESCRIPT('/soap/ajax/30.0/connection.js')}
//alert(new Date());
var connection = sforce.connection;
var newtask= new sforce.SObject("Task");
newtask.Subject = "Tried Calling";
newtask.WhoId="{!Lead.Id}";
newtask.Description="Tried calling, but could not get through";
newtask.ActivityDate= new Date();
newtask.Status="Completed";
//newtask.Type="Admin Call";
newtask.Priority="Low";
result = sforce.connection.create([newtask]);
alert(result );

I have tried the above code in my org and it is working as expected.

Please let me know if you face any issue with the above code.

Thanks,
Abhishek Bansal.

All Answers

Mahesh DMahesh D
var dealCloseDate = new Date({!YEAR(Deal_Registration__c.Close_Date__c)}, {!MONTH(Deal_Registration__c.Close_Date__c)} - 1, {!DAY(Deal_Registration__c.Close_Date__c)});

Please check the below post:

http://salesforce.stackexchange.com/questions/44988/javascript-button-date-to-date-nan-error

Regards,
Mahesh

 
Abhishek BansalAbhishek Bansal
Hi,

Please update your code with the below code :
{!REQUIRESCRIPT('/soap/ajax/30.0/connection.js')}
//alert(new Date());
var connection = sforce.connection;
var newtask= new sforce.SObject("Task");
newtask.Subject = "Tried Calling";
newtask.WhoId="{!Lead.Id}";
newtask.Description="Tried calling, but could not get through";
newtask.ActivityDate= new Date();
newtask.Status="Completed";
//newtask.Type="Admin Call";
newtask.Priority="Low";
result = sforce.connection.create([newtask]);
alert(result );

I have tried the above code in my org and it is working as expected.

Please let me know if you face any issue with the above code.

Thanks,
Abhishek Bansal.

This was selected as the best answer
The_A-RodThe_A-Rod
Perfect, thanks Abhishek!

I hadn't realised what the alert(result) command did, so I removed that and also added a location.reload() command on the end to refresh the page