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?