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
dukeduke 

How does one insert a task via Javascript / sforce Office Toolkit

Hey there,

 

Can anyone out there give me a few pointers on how one creates/inserts a new record within a contact's Activity History?  My situation is a follows:

  • I've developed an ActiveX control that performs some operations relating (potentially) to an sfdc contact or lead.
  • I want to lookup the contact/lead by its email address.
  • With that contact/lead ID in hand, I'd like to insert an entry (ie. task) within the Activity History of the contact or lead.
  • I am using Javascript.

Any help would be greatly appeciated!  Ae

Thanks in advance,

 

Duke

dukeduke

Also, is it correct to assume there isn't any documentation on the sforce office toolkit yet?  I read several other postings regarding this, which seem to indicate this.  I just thought I would double-check.

 

Duke

ScotScot

Duke,

I don't have it in javascript, but the following is an example of building a task in VBScript. If you don't get a javascript example, you can probably figure out what you need from this.

The example builds a task associated with an opportunity ...


'-------------------------------
'BuildTask - build a task for the owner of the opportunity
'-------------------------------
Sub BuildTask()

dim newtasks(0)
set newtasks(0) = binding.CreateObject("Task")

Dim i
Dim Xmsg
Xmsg = "** You have some problems to fix:" & vbNewLine
For i = 1 To UBound(Xerror)
   Xmsg = Xmsg & vbNewLine & " " & Xerror(i)
   Next

dim newtask ' individual task
for each newtask in newtasks
    newtask.Item("ActivityDate").value = dateadd("d",14,date())
    newtask.Item("Description").value = xmsg
    newtask.Item("OwnerId").value = opp.Item("OwnerId").value
    newtask.Item("Priority").value = "Normal"
    newtask.Item("SPIN_Type__c").value = "Continuation"
    newtask.Item("Status").value = "Not Started"
    newtask.Item("Subject").value = "Fix Problems"
    newtask.Item("WhatId").value = opp.Item("Id").value
    newtask.Item("Activity_Status__c").value = "Error Checking"
    next

dim r ' individual result
dim results ' array of results
dim errmsg ' error message string, built from each message
dim errors ' array of error objects
dim e ' individual error object
results = binding.Create(newtasks,false)
if binding.Error = 0 then
   msgbox("Ok, task created")
   else
   msgbox("Oops, task generation failed:" & vbcrlf & binding.errormessage & " (" & binding.error & ")")
   end if
end sub

dukeduke

Hey Scot,

Thanks!  That definitely helps.

Duke

ScotScot
Yes, unfortunately, there's no documentation. As you probably found in the other posts, you can get information about functions, events, properties and constants by viewing the SForceOfficeToolkitLib library. And you can use Ron's Connector code as a sample library.
dukeduke

Thanks Scot!  BTW - I posted another question related to my current effort, and I'd be curious to hear your thoughts.  It seems that the custom events fired by my activex control are not handled within either my vbscript or my javascript.  Interestingly, the events fire and are caught just fine when I run the control within a normal web page.  In other words, I can run the same control, same script and same IE browser in a regular HTML page, and the events are handled fine.  But as soon as I plop this within sfdc, no dice.  Have you ever tried and been successful in handling custom ActiveX events with an sforce control?  Just curious.  I also replaced my control with a stock MS control that fires custom events, that also did not work. Hmmmmm

Regards,

Duke

darozdaroz
I took a stab at your problem over here: http://forums.sforce.com/sforce/board/message?board.id=VB_development&message.id=678

Basically, I'm curious if you've taken into account that the integrations are actually displayed in an IFRAME on the SFDC page.
dukeduke

Thanks for your response.  No I haven't.  What are the implications of being within an IFrame?  Could this suppress or interfere with custom events?

 

Duke

MarkerVMarkerV
Were you ever able to create the javascript to do this? I have the same need and don't really want to reinvent the code if you've already translated the VB. I'll either be creating a new task and/or a new record in a custom object.

Thanks...
MarkerVMarkerV
I figured I'd post what I was able to make work.  Here's some code that you can stick in an S-Control, fill out the fields, click the button and a task will be created.  It's pretty bare-bones, but the launching point for me and thought it might be useful to others...

<script src="https://www.salesforce.com/services/lib/ajax/beta3.3/sforceclient.js" type="text/javascript"></script>
<script language="javascript">
<!--

function create_task()
 {

var assets = new Array(2);


sforceClient.init("{!API_Session_ID}", "{!API_Partner_Server_URL_70}");

                var object_2_create    = new Sforce.Dynabean("Task");

                //Set the fields on the Asset from the form element.
                var name = document.getElementById("TaskSubject")

                object_2_create.set("WhoId","{!Contact_ID}");

                object_2_create.set("Subject",name.value);

        //Call Create on the array of object_2_create records.
        var saveResult = sforceClient.Create(object_2_create);
        alert("Success")

 }


-->
</script>


<head>
    <title>Untitled Page</title>
</head>
<body>
<input type=button value="do this" onclick=create_task()><br>
Subject:  <input type =text id="TaskSubject"><br>
Contact Name:  <input type=text id="contact_name" value="{!Contact_FullName}"><br>
Contact ID:  <input type=text id="con_id" value="{!Contact_ID}"><br>
Address: <textarea id="addr_info">{!Contact_FullMailingAddress}</textarea><br>
Who's logged in:  <input type=text id="logged_in" value="{!User_Email}" disabled><br>

</body>
</html>