0

Does anyone know how to get the details of the parent automation from within an SSJS script?

We are looking to develop a generic SSJS script that can be used in multiple automations, but whose behaviour is defined by which actual automation is running it.

So looking for something like the ID of the Automation, or even AutomationActivity or AutomationActivityInstance which is executing the SSJS script.

The wsProxy documentation shows examples of retrieving these objects, but you need to pass in a filter referring to a specific item rather than using a 'this' for instance. It doesn't seem that the Core and Platform libraries can help much with what I am trying to achieve.

Has anyone done anything similar?

As an example of code that does not work

var prox = new Script.Util.WSProxy();
var cols = ["ActivityID","AutomationID","Status","AutomationInstance"];
var filter = {
    Property: "ActivityID",
    SimpleOperator: "equals",
    Value: this
};

var desc = prox.retrieve("AutomationActivityInstance", cols, filter);

This fails with

ExactTarget.OMM.InvalidFunctionParameterException: Null filter value supplied.

Clearly I can't supply 'this' as it seems to be undefined. I need a way of identifying the context under which this script activity is running.

  • what did try so far post here your code ? – pkharries Jul 29 '19 at 11:21
  • Well the issue is that I can't find a way to achieve what I am looking for. Have added some code that I know doesn't work but hopefully describes what I am trying to do – Husaam Maudarbocus Jul 30 '19 at 1:29
  • You could retrieve a list of running automations and make a 'best guess', but apart from that, I think what you're looking for isn't possible. – Josh de Blank Jul 30 '19 at 3:37
  • @JoshdeBlank - yes I went down that route, but the idea of a re-usable script is that it could be used by multiple automations that could be running at the same time - hence that approach won't work – Husaam Maudarbocus Jul 30 '19 at 5:37
1

Exactly what you are looking for does not exist.

What I do to replicate this ability is to create a content block code snippet that contains your SSJS code - keeping it ready for global use.

You then create a SSJS activity in each of these automations where you set the context there via a var and then use a 'ContentBlockByKey' call or something similar to pull in your code block to run the repeatable code.

For example:

Code block: (key: myExternalKey)

<script runat=server>

    if(myVar == "test") {

        Write('Wahooo')

    }else{

        Write('Boooo')

    }

</script>

Script activity:

<script runat=server>

    Platform.Load("Core","1.1.1");
    var myVar = 'test';

    var content = Platform.Function.ContentBlockByKey("myExternalKey");

    Write(TreatAsContent(content));    

</script>

This will cause the Script Activity to output Wahoo.

Using the SA to act as the 'input' or environmental setting and the content block as the function itself is the only way I am aware of to reuse code based on context.

  • Thanks @gortonington - that does look like the best option available within the platform currently. – Husaam Maudarbocus Jul 30 '19 at 23:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.