0

I am trying to move records from a DE into a custom object using an SSJS core function script (adapted from one I found here).

I have it working, but it leaves some records behind. Get's about 820 out of 935...well under the 2500 limit.

<script runat='server'>
Platform.Load("Core","1.1.1");

var records = DataExtension.Init("xxxxxxxx-xxxxxx-xxxxxx-xxxxxx-xxxxxxxx");
var data = records.Rows.Retrieve();
var datalength = data.length;


    
 for (var i = 0 ; i < data.length ; i ++) {
    var sf_fieldUpdateString = [];
 
    //sf_fieldUpdateString.push('Log_Created_Date__c');
    //sf_fieldUpdateString.push(data[i].CreatedDate);
   
    sf_fieldUpdateString.push('Transaction_ID__c');
    sf_fieldUpdateString.push(data[i].TransactionID);
  
    sf_fieldUpdateString.push('RecordTypeId');
    sf_fieldUpdateString.push('0126t000000gdzXXXX');
     
    sf_fieldUpdateString.push('MID__c');
    sf_fieldUpdateString.push(data[i].MID);
    
    sf_fieldUpdateString.push('EID__c');
    sf_fieldUpdateString.push(data[i].EID);
    
    //sf_fieldUpdateString.push('Federated_User_ID__c');
    //sf_fieldUpdateString.push(data[i].UserID);
   
    sf_fieldUpdateString.push('EmployeeID__c');
    sf_fieldUpdateString.push(data[i].EmployeeID);
   
    sf_fieldUpdateString.push('Employee_Name__c');
    sf_fieldUpdateString.push(data[i].EmployeeName);
   
    sf_fieldUpdateString.push('Object_Type_ID__c');
    sf_fieldUpdateString.push(data[i].ObjectTypeID);
   
    sf_fieldUpdateString.push('Object_Type_Name__c');
    sf_fieldUpdateString.push(data[i].ObjectTypeName);
   
    sf_fieldUpdateString.push('Operation_ID__c');
    sf_fieldUpdateString.push(data[i].OperationID);
   
    sf_fieldUpdateString.push('Operation_Name__c');
    sf_fieldUpdateString.push(data[i].OperationName);
   
    sf_fieldUpdateString.push('Object_ID__c');
    sf_fieldUpdateString.push(data[i].ObjectID);
   
    sf_fieldUpdateString.push('Object_Name__c');
    sf_fieldUpdateString.push(data[i].ObjectName);   
 
   var updateSFObject = "";
    updateSFObject += "\%\%[ ";
    updateSFObject += "set @salesforceFields = CreateSalesforceObject('UCSF_MC_Custom_Logs__c',12,";
    updateSFObject += "'" +  sf_fieldUpdateString.join("','") + "'";
    updateSFObject += ") ";
    updateSFObject += "output(concat(@salesforceFields)) ";
    updateSFObject += "]\%\%";
    
   
try
{

results = Platform.Function.TreatAsContent(updateSFObject);

} catch(e) {
   
} 

}
   
   
</script>

Any thoughts on why not getting all rows?

2
  • 1
    Hi Sean, welcome. Try comment out everything under the for loop and add to your script: Write("RetrievedRows: " + Stringify(data.length)). This will print the record number of rows retrieved. This way you can determine if the issue is related to your retrieve or your for loop, and then troubleshoot from there.
    – charliefay
    May 4 at 2:36
  • Could it be that the script fails to update the salesforce object at a particular point?
    – Ted Chan
    May 5 at 1:19

1 Answer 1

0

Whenever one of the SF functions is involved, it's most likely a problem in sales cloud - the numbers you give point to problems with individual records. This points to field validation.

Some of your records will run into validation limits (mandatory field is empty, restricted picklist does not allow value, a field does not allow you to access it...).

First I would print out / log the updateSFObject as text in each loop before executing the TreatAsContent.

That way you can see if some loops create inconsistent data - just to be sure.

Second, if you build a try-catch, make use of it. Right now, you are just managing the error (script doesn't break) but you aren't using the catch() for debugging. Particularly the SFSC function will give very precise error messages, just print / log them to a DE, read them and take it from there.

...
catch(e) {

    // Write(e)
   // Platform.Function.InsertData("someLogFile",["error"],[e])....
} 
...

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .