+ Start a Discussion
Nik_PNik_P 

Issues with an s-control which creates tasks....

Hey all...
 
Wrote this s-control, and I am going bug-eyed looking for the error, as it just isn't working.  Any comments from the experts???
 
Code:
<html> 
<head> 

<script language="JavaScript1.2" src="/js/functions.js"></script>
<script src="/soap/ajax/12.0/apex.js"></script>

<script>

function create_tasks_1()
{       
 //
 var Record = "{!Account.Id}";
 var RecordOwner = "{!Account.OwnerId}";
 //
 // Step 1 - Send Introduction Letter
 //
 var callarray=[];
 var callobj=new sforce.SObject("task");
 callobj.set("WhoId",Record);
 callobj.set("OwnerId",RecordOwner);
 callobj.set("Priority","Normal");
 callobj.set("Status","Not Started");
 callobj.set("Type","Type");
 callobj.set("Subject","Subject");
 callobj.set("Description","Description");
 callobj.set("ActivityDate",Date()+1);
 callarray.push(callobj); 
 var callcr = sforce.connection.create(callarray);
 for (var i=0; i<callcr.length ;i++ )
 {
    if (callcr[0].getBoolean("success")) 
    {
       //alert("Call - Success");
    } 
    else 
    {
       alert("Call - Failure");
    }
 }
parent.window.location.href = 'https://na3.salesforce.com/{!Account.Id}'; 

} 
</script> 

</head> 

<body>
<table width="100%"> 
<tr> 
<td align=center> 
<span class="moduleTitle">Creating Four Month Blitz... please wait</span> 
</td> 
</tr> 
<tr> 
<td>&nbsp;</td> 
</tr> 
<tr> 
<td align=center> 
<img src="/img/waiting_dots.gif" alt="Please wait..." title="Please wait..." width=196 height=20> 
</td> 
</tr> 
</table> 

<br /> 
<div id="output-div"></div> 

</body> 
</html>

 
Trying to run this S-Control off of a custom button on the account page - the final version will have about 10 tasks setup for them (using professional, so workflow is not available).
 
Thanks!
 
N
TCAdminTCAdmin
Hello Nik_P,

I am looking at your HTML and do not see where you are calling your script. You will need to include the following code somewhere in the HTML so that it calls the script
Code:
<script>create_tasks_1();</script>

 

TCAdminTCAdmin
Nik_P,

I also notice that you are using PE which does not have access to the API. This procludes you from being able to utilize any of the API calls, like create().
Nik_PNik_P
Ack - good point!  Would you have any recommendations on how you could automatically create tasks using PE using a custom link or button?
TCAdminTCAdmin

Nik_P,

With PE you will only have the ability to create a custom link to create a single task at a time. You may be able to use a loop and a custom link to save multiple records but I believe that timing would be an issue. A basic custom link with a window.location attribute can create and save a task. I'm not positive it would work but you may give it a try.

Code:
newWindow.location = '/00T/e?IsReminderSet=0&tsk3_lkid={!Account.Id}&tsk3={!Account.Name}&tsk5=new task&save=1';