Reputation: 43
I would like to update a record in the Sales Cloud object using Script in Automation Studio in Marketing Cloud.
I found the code: https://gist.github.com/katydorjee/818912244f95c49c0bf52c175d00cfe8. I've tried to apply it to my case, but it errors "ERROR: A runtime error occurred while the SSJS Activity executed the SSJS script. Please review the SSJS activity to ensure that errors are handled properly."
<script runat="server">
Platform.Load("core","1.1.1");
var sfUpdateString;
var targetDE = DataExtension.Init('xxx').Rows.Retrieve();
for (var i = 0; i < targetDE.length; i++)
{
var Field1 = targetDE[i].AccountID;
var Field2 = targetDE[i].Gender;
sfUpdateString = '';
sfUpdateString = '%'+'%[SET @uso = UpdateSingleSalesforceObject("Account","'+Field1+'"';
sfUpdateString += ',"Gender__c","'+Field2+'")]%'+'%';
Platform.Function.TreatAsContent(sfUpdateString);
Write(Platform.Variable.GetValue("@uso"));
}
</script>
Data Extension: |AccountID | Gender | | ------------------ | -------------- | | 0015g00000FwcXXXXX | Female |
Account (Salesforce Object):
Id = 0015g00000FwcXXXXX
Name = Mr. A
Gender__c(picklist field) = ' ' (I would like to update this field to be "Female")
Upvotes: 0
Views: 2763
Reputation: 43
I change "Platform.Load("core","1.1.1");" to "Platform.Load("core","1");" and it works well now.
Upvotes: 0