2

I would like to close the discussion thread on this related topic Manage automation via ampscript API. If you have additional information to complement it would be great to hear on the answers!

Here is my take, in case you would like to trigger an Automation via AMPSCript, or i.e. directly on the exclusion script from JB, or via CloudPage, you can follow the below instructions.

After some rounds of testing, I was able to fully confirm that ProgramID property throws 500 CP errors, therefore ObjectID is the property needed to invoke the InvokePerform function for the Automation Object.

%%[
set @obj = CreateObject("Automation")
SetObjectProperty(@obj, "ObjectID", "xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxx")
Set @performStatusCode = InvokePerform(@obj, "start", @performStatusMessage)
]%%
performStatusCode: %%=v(@performStatusCode)=%%
performStatusMessage: %%=v(@performStatusMessage)=%%

If you need to retrieve the ObjectID quickly, you can use the network in the developer console as per the attached screenshot below.

ObjectID

In case you would like to retrieve the ObjectID directly from AMPScript, you can use some filtering by the Automation name or CustomerKey.

  %%[

var @rr, @ObjectID, @queryDefinitions
set @rr = CreateObject("RetrieveRequest")
SetObjectProperty(@rr, "ObjectType", "Automation")
AddObjectArrayItem(@rr, "Properties", "Name")
AddObjectArrayItem(@rr, "Properties", "ProgramID")

set @sfp = CreateObject("SimpleFilterPart")
SetObjectProperty(@sfp, "Property", "Name")
SetObjectProperty(@sfp, "SimpleOperator", "equals")
AddObjectArrayItem(@sfp, "Value", "test-SSJS-assets")

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

set @queryDefinitions = InvokeRetrieve(@rr, @rrStatus, @rrRequestID)

output(concat("rrStatus: ", @rrStatus))
output(concat("<br>rrRequestID: ", @rrRequestID))

if rowcount(@queryDefinitions) > 0 then

  var @queryDefinition, @ObjectID, @obj

  set @queryDefinition = Row(@queryDefinitions, 1)
  set @ObjectID = Field(@queryDefinition, "ObjectID")

  set @obj = CreateObject("Automation")

  SetObjectProperty(@obj, "ObjectID", @ObjectID)
  Set @performStatusCode = InvokePerform(@obj, "start", @performStatusMessage)

endif

]%%

As per the below screenshot of the outcome, rendering the variables provides me an overall idea if the code was executed properly. enter image description here End note: Please make sure the Automation is in an active state.

1
  • 3
    Can you reformulate this to better adhere to the site's Q&A format?
    – Derek F
    Commented Jun 2, 2022 at 16:55

0

You must log in to answer this question.