I'm trying to update SF object (Lead) with 3 values in Script Activity in Automation Studio and also logging errors into DE but my code constantly fails. I added Catch/Try blocks but it didn't help and of course there is no changes on SF end.
Moreover - I got info from Support that I cannot update converted Lead record. Whether the Try/Catch block help me process the code or only detects and log the error?
Code:
<script runat="server">
Platform.Load("core","1");
var sfUpdateString;
var targetDE = DataExtension.Init('Contact_Deletion_Lead_UAT').Rows.Retrieve();
try{
for (var i = 0; i < targetDE.length; i++)
{
var Field1 = targetDE[i].ID;
var Field2 = targetDE[i].EmailBouncedReason;
var Field3 = targetDE[i].EmailBouncedDate;
var sfObj = "Lead";
sfUpdateString = '';
sfUpdateString = '%'+'%[SET @uso = UpdateSingleSalesforceObject("'+ sfObj +'","'+Field1+'"';
sfUpdateString += ',"EmailBouncedReason","'+Field2+'","RFMC__c","True","EmailBouncedDate", FormatDate("' + Field3 + '", "iso"))]%'+'%';
Platform.Function.TreatAsContent(sfUpdateString);
Write(Platform.Variable.GetValue("@uso"));
}
catch(e)
{
var logDE = DataExtension.Init("DeletionErrorLog");
var errorMsg = Stringify(e.message);
var errorDsp = Stringify(e.description);
logDE.Rows.Add({Id:Field1,Message:errorMsg, Description:errorDsp});
}
}