0

I was able to use the below code in one environment and I am getting the expected results. When I am trying to run the same (I did modify necessary things like change in DE external key, network ID etc) but it is giving me error I have added at the end of this.

<script runat="server">
    
    Platform.Load("core", "1.1");
    
    function logEr(logdesc){
    var updLog = Platform.Function.InsertData("LogError",["Error"],[logdesc]);
    createAutomationError();
    }
   
    function retreiveLoginHistory(ampStr) {
    var ampBlock = '\%\%['+ampStr+']\%\%';
    Platform.Function.TreatAsContent(ampBlock);
    return Variable.GetValue('@response');
    }
 
    try{
        var ampStr = "SET @time = FormatDate(DateAdd(Now(), -45, 'D'),'YYYY-MM-ddThh:mm:ss.000Z') "
                    + "SET @retrieve = RetrieveSalesforceObjects('LoginHistory', 'Id, UserId, LoginTime, NetworkId', 'NetworkId', '=', '0DB1N000000CausUBC') " 
                    +"SET @rowCount = RowCount(@retrieve) " 
                    +"SET @response = '' "
                    +"IF @rowCount > 0 THEN " 
                    +"FOR @counter = 1 TO @rowCount DO " 
                    +"SET @row = Row(@retrieve, @counter) "
                    +"SET @id = Field(@row, 'Id') "  
                    +"SET @userId = Field(@row, 'UserId') "
                    +"SET @loginTime = Field(@row, 'LoginTime') " 
                    +"SET @networkId = Field(@row, 'NetworkId') "
                    +"SET @rowData = Concat(@id, ',' ,@userId, ',' ,@loginTime, ',' ,@networkId) "
                    +"SET @response = Concat(@response, @rowData, ';') "
                    +"NEXT @counter ENDIF";
        var response = retreiveLoginHistory(ampStr);
        response = response.split(';');
        var loginData = [];
        for (var i = 0; i < response.length - 1; i++) {
            var data = response[i].split(',');
            loginData.push({
                Id: data[0],
                UserId: data[1],
                LoginTime: data[2],
                NetworkId: data[3]
            });
        }
        
        var scriptDE = DataExtension.Init("29322B8B-C0D5-43B6-840E-BE0E9F093E43");
        scriptDE.Rows.Add(loginData);
    }
    catch(e){
    var logdesc = "Exception occurred: " + Stringify(e);
    logEr(logdesc);
}
</script>

It seems there are two exceptions and one error: Exception 1 related to TreatAsContent function call Exception 2 related to Concat used where error says it can't concat more than 50k characters.

But in the environment I tested before there were no such exceptions. I don't get the cause where it is going wrong, please suggest.

Exception occurred: {"message":"An error occurred when attempting to evaluate a TreatAsContent function call. See inner exception for details.","description":"ExactTarget.OMM.FunctionExecutionException: An error occurred when attempting to evaluate a TreatAsContent function call. See inner exception for details.\r\n Error Code: OMM_FUNC_EXEC_ERROR\r\n - from Jint --> \r\n\r\n --- inner exception 1---\r\n\r\nExactTarget.OMM.FunctionExecutionException: An error occurred when attempting to evaluate a Concat function call. See inner exception for details.\r\n Error Code: OMM_FUNC_EXEC_ERROR\r\n

  • from OMMCommon --> \r\n\r\n --- inner exception 2---\r\n\r\nExactTarget.OMM.FunctionExecutionException: Cannot CONCAT more than 500000 characters.\r\n Error Code: OMM_FUNC_EXEC_ERROR\r\n
  • from OMMCommon\r\n\r\n\r\n\r\n\r\n\r\n"}
1
  • If you set the for loop only has 1 iteration, something like this FOR @counter = 1 TO 1 DO . What does it say?
    – Duc Le
    Jan 20 at 12:58

1 Answer 1

0
for @counter = 1 to @rowCount do

This will repeat in a loop for as many times as defined in rowCount

You must log in to answer this question.

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