0

I have a triggered send email consisting of Ampscript, in this template we are using a lot of personalization which is coming through XML in the triggered send data extension. So the issue is if the triggered send fails in background it tries 3-4 times and then MC pauses the triggered send definition.

In such error scenario the admin should at least know about the error and for that what I am trying is adding try catch to the email template Ampscript using SSJS, and with that in the catch block I am trying to insert error logs in a data extension, after that i have written a script which will fetch the error log Data extensions data into a triggered send Data extension and an email with the error will should be sent to the admin(which is a hard-coded value),I am not sure whether I am going correct or not.

I just want the error to be sent to an admin if the template throws any.

Adding a part of the code with try catch block(kindly see the first two lines which are not getting highlighted in the code, its :

<script runat="server" type="text/javascript">
    Platform.Load("core","1"); 
    try { ):

<script runat="server" type="text/javascript">
    Platform.Load("core","1"); 
    try {
    </script>
    <!--%%[

        set @subkey = _subscriberkey 
    var @orderxml, @orderdate, @ordernumber, @order, @FirstName, @LastName

             SET @orderxml = AttributeValue("Order XML")




                  IF NOT EMPTY(@orderxml) THEN

                SET @FullName = BuildRowSetFromXML(@orderxml, "/order/contact/contact-name", 0), 1)
                SET @FullName = IIF(RowCount(@FullName), Field(Row(@FullName, 1), "Value"), "")

                IF IndexOf(@FullName, " ") > 0 THEN
                    SET @FirstName = Substring(@FullName,1,Subtract(IndexOf(@FullName," "),1))
                    SET @LastName = Substring(@FullName,Add(IndexOf(@FullName," "),1))
                    ELSE
                    SET @FirstName = @FullName
                ENDIF


             ENDIF


    ]%%-->
    <script type="text/javascript" runat="server">
    var sub = Platform.Variable.GetValue("@subkey");
    Write("<br>sub: " + sub);

    }
    catch(ex){
        Write('<br>Exception======='+ex);
        var rows = Platform.Function.InsertData("ErrorLogs",["SubscriberKey","ErrorOrException","ErrorDate","Source"],[sub,", Exception: "+Stringify(ex),new Date(),"Order Confirmation Template-bAddrState"]);
        var data = {
                    attributes : {
                ErrorOrException: Stringify(ex),
                Source: "Etude_Err_Logs_Order_Confirmation_CE"
            },
            subscriber : {
                EmailAddress: "abc@test.com",
                SubscriberKey: sub
            }


        }
                    var TSD = TriggeredSend.Init("Etude_Err_Logs_Order_Confirmation_CE");
                    var Status = TSD.Send(data.subscriber,data.attributes);

                if(Status != "OK") {
                    Write("(!) Error: " + Stringify(Status));
                } else {
                    Write("(+) Great success!");
                }

    </script>

    <!-- %%[

         /* not required */ 

      ]%%-->

    <script type="text/javascript" runat="server">
    }
    </script>  

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.