0

I need to get the status of the last run of an automation through SSJS.

The context: there are several automations that will run and if all of them are successful I need to start another automation which ends the processing. I am using a SSJS script in order to do the same.

If any of the automation runs fail, I need to fail the script.

Problem I'm facing is: when i retrieve the automation object, its status is coming up as 2 (which means Ready) even when the last run fails. So I think if I retrieve automation instance object instead, I will be able to see the status as -1 (which means error) in case the automation run errors out.

Please assist in how to get this done in SSJS activity.

0

I was not able to do so using SSJS but using SOAP api, then retrieving "AutomationInstance" Object. See: https://developer.salesforce.com/docs/atlas.en-us.mc-apis.meta/mc-apis/automationinstance.htm With this you can retrieve ALL the automation runs with its statuses

 <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" 
  xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <s:Header>
        <o:Security xmlns:o="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" s:mustUnderstand="1">
            <o:UsernameToken u:Id="uuid-4e7d733b-f16d-44e1-b947-b27ce4cda3fe-1">
                <o:Username>MYUSERNAME</o:Username>
                <o:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">MYPWD</o:Password>
            </o:UsernameToken>
        </o:Security>
    </s:Header>
    <s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
        <RetrieveRequestMsg xmlns="http://exacttarget.com/wsdl/partnerAPI">
            <RetrieveRequest>
                <!--ClientIDs>
               <ClientID>7293635</ClientID>
            </ClientIDs-->
                <ObjectType>AutomationInstance</ObjectType>                       
                <Properties>Name</Properties>
                <Properties>AutomationType</Properties>
                <Properties>Status</Properties>
                <Properties>CompletedTime</Properties>
                <Filter xsi:type="SimpleFilterPart">
                    <Property>Name</Property>
                    <SimpleOperator>IN</SimpleOperator>    
                    <Value>AUTOMATION NAME 1</Value>
                    <Value>AUTOMATION NAME 2</Value>
                    <!--Property>CompletedTime</Property>
                    <SimpleOperator>equals</SimpleOperator>
                    <DateValue>2018-01-08T11:27:36.27</DateValue-->
                </Filter>
            </RetrieveRequest>
        </RetrieveRequestMsg>
    </s:Body>
</s:Envelope>

Note that in a production environment you should use a token, instead of the username/pwd.

In the response you'll have all the runs of a given set of automations, then you should get the latest. I was not able filter using CompletedTime field, it gives me the error: Object reference not set to an instance of an object, and as it is stated in the documentation its not possible to use a complexfilterpart with this request.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.