3

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);
3
  • I'm following the official "create automation with soap api" example, but it's not working in SSJS: code.exacttarget.com/apis-sdks/soap-api/…
    – Michael
    Apr 24, 2015 at 15:07
  • The InvokeCreate method in Server-Side JavaScript first input parameter is the object you want to create, not a CreateRequest object. Change the InvokeCreate line to replace "CreateRequest" with "Automation".
    – Mac
    Apr 24, 2015 at 15:59
  • Thanks, Mac. That cleared up the error. It seems the CreateRequest object is not available through the platform. Now that I've replaced it with Automation in the InvokeCreate line, there is a new error: "An error has occurred: {"message":"Unable to retrieve security descriptor for this frame.","description":"System.InvalidOperationException: Unable to retrieve security descriptor for this frame. - from mscorlib\r\n\r\n"}". I encountered this error before in an InvokeRetrieve -- the solution there was to use a RetrieveRequest object as the first parameter, not an API object.
    – Michael
    Apr 24, 2015 at 17:55

1 Answer 1

2

You are only passing two parameters into InvokeCreate. That function requires three parameters, otherwise you'll get the error you are seeing.

That error basically means it can't find a function with the name specified or the method signature doesn't match.

It should look something like:

var p = [0,0];
var status = Platform.Function.InvokeCreate(AutomationTaskOne, p, null);
var message = p[0];
var errorCode = p[1];
1
  • 1
    Thanks Kelly!! You saved me. Really, a huge relief. Thanks again!
    – Michael
    Apr 27, 2015 at 20:53

You must log in to answer this question.

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