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
pickerpicker 

Create an event using AJAX

Can anyone tell me why this bit of code does not create a new event?
 
<script src="https://www.salesforce.com/services/lib/ajax/beta3.3/sforceclient.js" type="text/javascript"></script>
<script type="text/javascript" src="https://na1.salesforce.com/js/functions.js"></script>
<script>
sforceClient.init("{valid session id}", "{valid server}", true);
var vappt;
vappt = new Sforce.Dynabean("event");
vappt.set("WhoId","{valid contact id}");
vappt.set("WhatId","{valid account id}");
vappt.set("Subject","Appointment Set");
vappt.set("Location","ADDRESS NOT FOUND");
vappt.set("IsAllDayEvent","false");
vappt.set("ActivityDateTime",new Date("2006-08-02T13:00:00+00:00"));
vappt.set("DurationInMinutes","30");
vappt.set("Description","anything");
var appt_sr2 = sforceClient.create([vappt])[0];
</script>
jf317820jf317820
the merge fields inside your { } don't look to be valid.  i don't know whether this is the exact code you're testing or not, but i'm sure that the code you attached in this post wouldn't run properly.
Ron HessRon Hess
add an alert message to look at the return value from the create call, that is where an error or fault message would be found

so,

alert(appt_sr2.toString())

mabey take off the [0] at the end of the create() to see the entire fault message
pickerpicker
jf:
 
I replaced all the data inside the { } for the post.  But there is valid values in there in my actual code.
 
Ron:
 
Thanks for the tip, becuase i was unable to get this thing to give me the error message without taking out that [0].
The error message i recieve now is :
 
detail:
type: 
fault:
exceptionMessage:
exceptionCode:
className: fault
className: detail
faultstring: 'NaN-NaN-NaNTNaN:NaN:NaN-NaN:NaN' is not a valid value for the type xsd:dateTime
faultcode:
soapenv:Client
className: Fault
 
It appears that this line is causing the problem:
vappt.set("ActivityDateTime",new Date("2006-08-02T13:00:00+00:00"));
 
If i change this line to:
vappt.set("ActivityDateTime","2006-08-02T13:00:00+00:00");
then i get the error: "Exception thrown and not caught" on line 3660, which is way out of range of my code.  I can only assume that this is an error being generated from salesforce code.  Do i have a valid format for the datetime?
pickerpicker

OK, i found the solution.  The confusion came about because i am using both the java API and the ajax API.  The dateTime string that i was trying to use is formatted correctly if i were using java.  For AJAX and javascript, i did this:

 


var vdate = new Date();
                       vdate.setYear("2006");
                       vdate.setMonth("07");
                       vdate.setDate("05");
                       vdate.setHours("13");
                       vdate.setMinutes("00");
                       vdate.setSeconds("00");
                       document.write(vdate);

vappt.set("ActivityDateTime",vdate);

Ron HessRon Hess
A quick search in the AJAX Beta3.3 source will produce several Date utilties

look for Sforce.Util.parseDate() and you will find it, and several other usefull date routines.