1

I am trying to create a Sales/Service Cloud task for our sales reps when someone clicks or opens an email in a journey. The desire is to use an API call for two reasons: 1.) to eliminate the need for a wait step to collect clicks, thus getting the task to the sales rep sooner, 2.) simplify the journey canvas.

My data view query is working - but my opens/clicks SSJS is failing. Automation Studio won't tell me why. I am still learning SSJS - if someone has an answer, would you mind sharing how you got to the solution? Please note I have placed more generic names in place of actual folder names or data extension names.

Below is my AMPscript code (using in a Content Block):

%%[

SET @rows = LookupRows("Data_Extension_Name","TaskCreated","False") 
for @i = 1 to RowCount(@rows) do 
     SET @row = ROW(@rows, @i) 
     SET @contactId = Field(@row,"Subscriber_Key")
     SET @salesrep = Field(@row,"Sales_Rep_Name")  
     SET @click = Field(@row,"ClickFlag") 
     SET @open = Field(@row,"OpenFlag") 
     SET @related = Field(@row, "CampaignId")
     SET @duedate = Field(@row, "Due_Date")
     SET @cancreate = "False"

     IF @click = True THEN
        SET @description = "Some description"
        SET @cancreate = "True"

     ELSE

        IF @open = True THEN
           SET @description = "Some description"
           SET @cancreate = "True"

        ENDIF

     ENDIF

     IF @cancreate = "True" THEN
         SET @Id=CreateSalesforceObject("Task",9,
          "ContactId",@contactId,
          "WhatId", @related,
          "Subject","Subject of task.",
          "Status","Open",
          "Priority","Normal",
          "Description", @description,
          "RecordType", "012610000007HpjAAE",
          "Task_Activity_Type__c", "Marketing Cloud Journey",
          "ActivityDate", @duedate)

          UpdateData('Data_Extension_Name',1,'Subscriber_Key',@contactId,'TaskCreated',"True")

      ENDIF

   next @i

]%%

**SSJS built in Script of Automation Studio:** 

<script runat="server">
    Platform.Load("core","1");
    TreatAsContent(Platform.Function.ContentBlockByName("Content Builder\\folder name\\folder name\\folder name\\folder name\\folder name\\folder name\\folder name\\name of content block"));
</script>

6
  • Not sure it will really solve your issue but I usually use ContentBlockByID() as it has less risk if someone moves the block from the folder or changes name/key that the call will then fail. From there I usually comment the path to it underneath for easy reference. I am not sure why you are putting double slashes in the ContentBlockByName info - but it should only be single slash for each directory I believe. – Gortonington May 22 '20 at 18:26
  • you could also use a webhook and process that action – EazyE May 22 '20 at 18:50
  • @Gortonington - thanks for the tip. I tried using the ContentBlockbyId and it still failed ` <script runat="server"> Platform.Load("core","1"); TreatAsContent(Platform.Function.ContentBlockbyId("10836")); </script> ` – Kim May 22 '20 at 19:21
  • have you tried running the AMPscript on a Cloudpage or something and seeing if you can get an error message out of it that way? Only other place I would look is if your @rows lookup is returning 0 or empty, it would error out your script – Gortonington May 22 '20 at 19:48
  • Looking at the Task object in Salesforce, there is no such field as 'ContactID'. You need to set the field WhoId in the task. So... SET @Id=CreateSalesforceObject("Task",9, "WhoId",@contactId, – MarcDBehr Jun 9 '20 at 14:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.