Salesforce Asked by MrViSiOn on January 16, 2021
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?
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
Answered by Scott L. on January 16, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP