Advertisement
MrViSiOn

Automation Studios SSJS

Sep 6th, 2017
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.54 KB | None | 0 0
  1. // Prepare ImportDefinition for Automation (See Automation Below)
  2. var ImportDefinition = Platform.Function.CreateObject("ImportDefinition");
  3. Platform.Function.SetObjectProperty(ImportDefinition, "CustomerKey", "SSJS_Import");
  4. Platform.Function.SetObjectProperty(ImportDefinition, "Name", "SSJS_Import");
  5.  
  6. // Build the Automation
  7. var Automation = Platform.Function.CreateObject("Automation");
  8. var AutomationName = "TempAutomation";
  9. Platform.Function.SetObjectProperty(Automation, "Name", AutomationName);
  10. Platform.Function.SetObjectProperty(Automation, "CustomerKey", AutomationName);
  11. Platform.Function.SetObjectProperty(Automation, "AutomationType", "scheduled");
  12.  
  13. // Build Automation Import Activity (For Step One)
  14. var ImportActivity = Platform.Function.CreateObject("AutomationActivity");
  15. Platform.Function.SetObjectProperty(ImportActivity, "Name", "SSJS_Import");
  16. var APIObject = Platform.Function.CreateObject("APIObject");
  17. Platform.Function.SetObjectProperty(ImportActivity, "Definition", APIObject);
  18. Platform.Function.SetObjectProperty(ImportActivity, "ActivityObject", ImportDefinition);
  19.  
  20. // Build Automation Task: Task One
  21. var AutomationTaskOne = Platform.Function.CreateObject("AutomationTask");
  22. Platform.Function.SetObjectProperty(AutomationTaskOne, "Name", "Task One");
  23. Platform.Function.AddObjectArrayItem(AutomationTaskOne, "Activities", ImportActivity);
  24. Platform.Function.AddObjectArrayItem(Automation, "AutomationTasks", AutomationTaskOne);
  25.  
  26. // Create Automation
  27. // The next 4 lines would use the CreateRequest object, but this object is not available in the SSJS platform. Can it be?
  28. //var CreateRequest = Platform.Function.CreateObject("CreateRequest");
  29. //var CreateOptions = Platform.Function.CreateObject("CreateOptions");
  30. //Platform.Function.SetObjectProperty(CreateRequest, "Options", CreateOptions);
  31. //Platform.Function.AddObjectArrayItem(CreateRequest, "Objects", Automation);
  32.  
  33. var StatusAndRequestID = [0,0];
  34. var CreateResults = Platform.Function.InvokeCreate(Automation, StatusAndRequestID);
  35.  
  36. // The line above doesn't play well with API Objects such as Automation or ImportDefinition. It would work with a CreateRequest object, but that object type is unavailable.
  37.  
  38. // The code on this page is running behind the scenes on this page and the error at the top is the error for this code. It wants a security descriptor. I think this is inside of the CreateRequest object.
  39.  
  40.  
  41.  
  42.  
  43.  
  44. //Probar esto
  45. var p = [0,0];
  46. var status = Platform.Function.InvokeCreate(AutomationTaskOne, p, null);
  47. var message = p[0];
  48. var errorCode = p[1];
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement