2

I am attempting to retrieve the status of an automation in a Business Unit with the following AMPscript, but I haven't been successful yet. Could someone please assist?

%%[

SET @key = "###"
SET @mid = "###"
SET @rr = CreateObject("RetrieveRequest")

SET @clientid = CreateObject("ClientID")
SetObjectProperty(@clientid,"ID",@mid)
AddObjectArrayItem(@rr,"ClientIDs",@clientid)

SetObjectProperty(@rr,"QueryAllAccounts",1)

SetObjectProperty(@rr, "ObjectType","Automation")
AddObjectArrayItem(@rr,"Properties","ProgramID")
AddObjectArrayItem(@rr,"Properties","Name")
AddObjectArrayItem(@rr,"Properties","CustomerKey")
AddObjectArrayItem(@rr,"Properties","CreatedDate")
AddObjectArrayItem(@rr,"Properties","Description")
AddObjectArrayItem(@rr,"Properties","IsActive")
AddObjectArrayItem(@rr,"Properties","Status")
AddObjectArrayItem(@rr,"Properties","ScheduledTime")

SET @sfp = CreateObject("SimpleFilterPart")
SetObjectProperty(@sfp, "Property", "CustomerKey")  
SetObjectProperty(@sfp, "SimpleOperator", "equals")  
AddObjectArrayItem(@sfp, "Value", @key)    

SetObjectProperty(@rr, "Filter", @sfp)

SET @automations = InvokeRetrieve(@rr)

FOR @c = 1 TO RowCount(@automations) DO
    SET @row = Row(@automations ,@c)
    SET @autoCustomerKey = Field(@row,"CustomerKey")
NEXT @c

]%%

CustomerKey : %%=v(@autoCustomerKey)=%%

The above code returns:

CustomerKey :

I would like to retrieve the statuses of the Automations in all Business Units to create a Landing Page dashboard. The Landing Page would be in the top level Business Unit.

3 Answers 3

3

I haven't found a way to do this in AMPScript, but you can do it with SSJS:

<script runat="server">

Platform.Load("Core","1.1.1");
var output = "";

var automationCustomerKey = "DECUSTOMERKEY"

var rr = Platform.Function.CreateObject("RetrieveRequest");
Platform.Function.SetObjectProperty(rr, "ObjectType", "Automation");
Platform.Function.AddObjectArrayItem(rr, "Properties", "ProgramID");
Platform.Function.AddObjectArrayItem(rr, "Properties", "CustomerKey");
Platform.Function.AddObjectArrayItem(rr, "Properties", "Status");

var sfp = Platform.Function.CreateObject("SimpleFilterPart");
Platform.Function.SetObjectProperty(sfp, "Property", "CustomerKey");
Platform.Function.SetObjectProperty(sfp, "SimpleOperator", "equals");
Platform.Function.AddObjectArrayItem(sfp, "Value", automationCustomerKey);

Platform.Function.SetObjectProperty(rr, "Filter", sfp);

var retrieveStatus = [0,0,0];

var automationResultSet = Platform.Function.InvokeRetrieve(rr, retrieveStatus);
//output += "<br>automationResultSet: " + Stringify(automationResultSet);

var ObjectID = automationResultSet[0]["ObjectID"];
var Status = automationResultSet[0]["Status"];

if (ObjectID != "null") {

    output += "<br>" + automationCustomerKey + " ObjectID : " + ObjectID;
    output += "<br>" + automationCustomerKey + " Status: " + Status;

    /*
    Code Status
    -1   Error
     0   BuildingError
     1   Building
     2   Ready
     3   Running
     4   Paused
     5   Stopped
     6   Scheduled
     7   Awaiting Trigger
     8   InactiveTrigger
    */

} else {
  output += "<br>" + automationCustomerKey + " not found";

}

Write("<br>" + output);

</script>

Output

DECUSTOMERKEY ObjectID : xxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxx
DECUSTOMERKEY  Status: 6
5
  • I'm not seeing how this retrieves from a Child BU? Commented Oct 5, 2016 at 21:13
  • @victorcorey I don't think you can cross business unit lines with a Script Activity, if that's what you're trying to do. Commented Oct 5, 2016 at 22:51
  • @AdamSpriggs cross business unit is possible. Check out the answer below.
    – Ali Nahid
    Commented Jun 29, 2017 at 5:12
  • @AdamSpriggs I know this is old but is there a way for it to do this for EVERY automation you have set up, in a loop?
    – TCassa
    Commented Jan 14, 2019 at 14:59
  • @TCassa, sure, you just don't specify a filter in your retrieve. Commented Jan 14, 2019 at 17:28
2

This post is pretty old but going to answer regardless in case it helps anyone else.

So it is possible to trigger automation from one business unit to other business unit (as long as the permission exists).

I followed Adam's answer with a slight modification that addresses targeting business unit.

The trick here is to use "Program" instead of "Automation".

Hope it helps.

var cid = Platform.Function.CreateObject("ClientID");
Platform.Function.SetObjectProperty(cid, "ID", buMID);
Platform.Function.SetObjectProperty(cid, "IDSpecified", "true")

var rr = Platform.Function.CreateObject("RetrieveRequest");
Platform.Function.AddObjectArrayItem(rr, "ClientIDs", cid);
Platform.Function.SetObjectProperty(rr, "ObjectType", "Program");
Platform.Function.AddObjectArrayItem(rr, "Properties", "Name");
Platform.Function.AddObjectArrayItem(rr, "Properties", "ObjectID");
Platform.Function.AddObjectArrayItem(rr, "Properties", "Status");


var sfp = Platform.Function.CreateObject("SimpleFilterPart");
Platform.Function.SetObjectProperty(sfp, "Property", "CustomerKey");
Platform.Function.SetObjectProperty(sfp, "SimpleOperator", "equals");
Platform.Function.AddObjectArrayItem(sfp, "Value", automationCustomerKey);

Platform.Function.SetObjectProperty(rr, "Filter", sfp);


var retrieveStatus = [0,0,0];

var automationResultSet = Platform.Function.InvokeRetrieve(rr, retrieveStatus);
Write(Stringify(automationResultSet));

if(automationResultSet  != null) {
 var automationObjectID = automationResultSet[0]["ObjectID"];
 var automationStatus = automationResultSet[0]["Status"];
}



if (automationObjectID != "null") {

    // found you !!

} else {
   // automation not found
}
1
  • Programs are nearly all deprecated. Commented Jun 29, 2017 at 14:13
0

Here's how target a child BU with AmpScript. Thanks to @Ali for his JS, it helped me figure this out.

Set @client = CreateObject("ClientID")
SetObjectProperty(@client,"ID",100032392)
SetObjectProperty(@client,"IDSpecified","true")

SetObjectProperty(@sd,"Client",@client)

Not sure if you need the "IDSpecified"

You must log in to answer this question.

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