I've created a server-side JavaScript activity to create an automation, which is throwing an error:
An error has occurred: {"message":"An error occurred when attempting to evaluate a CreateObject function call. See inner exception for details.","description":"ExactTarget.OMM.FunctionExecutionException: An error occurred when attempting to evaluate a CreateObject function call. See inner exception for details.\r\n Error Code: OMM_FUNC_EXEC_ERROR\r\n - from Jint --> \r\n\r\n --- inner exception 1---\r\n\r\nSystem.TypeLoadException: Could not load type 'ExactTarget.Integration.WSDL.CreateRequest' from assembly 'ExactTarget.Api.Generated'. - from mscorlib\r\n\r\n\r\n\r\n"}
I haven't see much support on this subject via Google search. Has anyone been able to create an automation through SSJS yet?
Here is my code. It is running here: http://pub.s1.exacttarget.com/a5ozcerrjn2
I'm hoping that someone with more experience can lend a hand. The automation begins after the import definition is retrieved. The automation object is not playing nicely with the createrequest object. Any and all help is appreciated.
Platform.Load("core","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 = "TempAutomation";
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 APIObject = Platform.Function.CreateObject("APIObject");
Platform.Function.SetObjectProperty(ImportActivity, "Definition", APIObject);
Platform.Function.SetObjectProperty(ImportActivity, "ActivityObject", ImportDefinition);
// Build Automation Task: Task One
var AutomationTaskOne = Platform.Function.CreateObject("AutomationTask");
Platform.Function.SetObjectProperty(AutomationTaskOne, "Name", "Task One");
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 CreateResults = Platform.Function.InvokeCreate(CreateRequest, StatusAndRequestID);