1

Is it possible to create an automation by SSJS, object type CreateRequest does not exist and I don't know how create that entity in my system.

I using this code but last lines gives me an error.

<script runat="server">

Platform.Load("Core","1.1.1");

// Retrieve the Import Definition for the Import Activity of the Automation
var RetrieveRequest = Platform.Function.CreateObject("RetrieveRequest");
Platform.Function.SetObjectProperty(RetrieveRequest, "ObjectType", "ImportDefinition");
Platform.Function.AddObjectArrayItem(RetrieveRequest, "Properties", "CustomerKey");
Platform.Function.AddObjectArrayItem(RetrieveRequest, "Properties", "ObjectID");
Platform.Function.AddObjectArrayItem(RetrieveRequest, "Properties", "Name");

var SimpleFilterPart = Platform.Function.CreateObject("SimpleFilterPart");
Platform.Function.SetObjectProperty(SimpleFilterPart, "Property", "CustomerKey");
Platform.Function.SetObjectProperty(SimpleFilterPart, "SimpleOperator", "equals");
Platform.Function.AddObjectArrayItem(SimpleFilterPart, "Value", "SSJS_Import");
Platform.Function.SetObjectProperty(RetrieveRequest, "Filter", SimpleFilterPart);

var StatusAndRequestID = [0,0];
var ImportDefinition = Platform.Function.InvokeRetrieve(RetrieveRequest, StatusAndRequestID);

//Write(Stringify(ImportDefinition))

// Build the Automation
var Automation = Platform.Function.CreateObject("Automation");
var AutomationName = "TempAutomation2";
Platform.Function.SetObjectProperty(Automation, "Name", AutomationName);
Platform.Function.SetObjectProperty(Automation, "CustomerKey", AutomationName);
Platform.Function.SetObjectProperty(Automation, "AutomationType", "scheduled");

// Build Automation Import Activity (For Step One)
var ImportActivity = Platform.Function.CreateObject("AutomationActivity");
Platform.Function.SetObjectProperty(ImportActivity, "ObjectID", ImportDefinition.ObjectID);
Platform.Function.SetObjectProperty(ImportActivity, "Name", ImportDefinition.Name);

var DefinitionObject = Platform.Function.CreateObject("APIObject");

Platform.Function.SetObjectProperty(ImportActivity, "Definition", DefinitionObject);

var ImportDefinitionObject = Platform.Function.CreateObject("APIObject");
Platform.Function.SetObjectProperty(ImportDefinitionObject, "ObjectID", ImportDefinition.ObjectID);
Platform.Function.SetObjectProperty(ImportDefinitionObject, "CustomerKey", ImportDefinition.ObjectID);

Platform.Function.SetObjectProperty(ImportActivity, "ActivityObject", ImportDefinitionObject);

// Build Automation Task: Task One
var AutomationTaskOne = Platform.Function.CreateObject("AutomationTask");
Platform.Function.AddObjectArrayItem(AutomationTaskOne, "Activities", ImportActivity);
Platform.Function.AddObjectArrayItem(Automation, "AutomationTasks", AutomationTaskOne);


// Create Automation
var CreateRequest = Platform.Function.CreateObject("CreateRequest");
var CreateOptions = Platform.Function.CreateObject("CreateOptions");
Platform.Function.SetObjectProperty(CreateRequest, "Options", CreateOptions);
Platform.Function.AddObjectArrayItem(CreateRequest, "Objects", Automation);


var StatusAndRequestID = [0,0];
var r;
var CreateRequests = Platform.Function.InvokeCreate(CreateRequest, StatusAndRequestID, r);

Write(Stringify(CreateRequests))
</script>

What am I doing wrong here?

2
  • Please edit your question and include the exact error message you are getting, so finding an error is far easier for the community. Thank you! Commented Sep 14, 2017 at 8:32
  • Thank you... I'm executing this code in a cloud page and I get error 500 with no more info... How can I debug better?
    – MrViSiOn
    Commented Sep 14, 2017 at 11:32

1 Answer 1

0

I realize that this is old but there may be a couple of issues. First is that AutomationTasks is read-only so cannot be set in this manner. Additionally the objects AutomationActivity and AutomationActivityIntance listed in the documentation cannot be referenced by these names. They must be referenced as Activity and ActivityInstance. The documented object names are incorrect. https://developer.salesforce.com/docs/atlas.en-us.mc-apis.meta/mc-apis/automationactivity.htm

You must log in to answer this question.

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