How to pass more than 2 parameters from workflow 'Create Event' activity?

Jeff316
Kilo Guru

 I have a 'create event' activity in my workflow to trigger an email. That works fine. I need to get 4 variables from the catalog request down to the email notification. These 4 variables are reference fields pointing to users who need to be notified.  I know I can pass 2 parameters so how do I pass 4 variables to the email notification triggered by the event?

1 ACCEPTED SOLUTION

Hi Jeff316,

I got it now actually you need to send the notification to the param1 values which is multiple here.

So here you don't need the object part you can simply write the following script in the event1 param field of the create event activity as:

(function() {
var arr= [];

arr.push(current.variables.owned_by);
arr.push(current.variables.managed_by);
arr.push(current.variables.primary_product_owner);
arr.push(current.variables.requested_for.requester_name);

return arr.toString();

}());

We are storing all the users in an array and returning that array to the event param1.

If it helps then please mark my answer Correct and Helpful.

Thanks,

CB

 

View solution in original post

8 REPLIES 8

Rishabh Jha
Mega Guru

Hi Jeff,

You should be able to construct a json object from the data values that you need to pass, and then pass it as a json string in a single event parameter. You can then parse it back as a json object in your notification script, and get the values there from the parsed json object properties.

Something like:

var objArr = [];
var obj1 = {'keyName' : 'val1'};
var obj2 = {'keyName' : 'val2'};
var obj3 = {'keyName' : 'val3'};
objArr.push(obj1);
objArr.push(obj2);
objArr.push(obj3);

var jsonObj = JSON.stringify(objArr);


gs.eventQueue('your.event.name', current, jsonObj);

 

In Notification script:

var objArr = JSON.parse(event.parm1);

for (var i = 0; i < objArr.length; i++) {

template.print('key-val'+i+ ':' + objArr[i].keyName);

}


Thanks & Regards,
Rishabh Jha
Aavenir(https://www.aavenir.com/)

Hello Rishabh,

Thanks for the help.

I was going to use a "Create Event" activity, but I can use a run script instead to call my event.

I'm familiar with notification scripts and use them, but in this case how does the email notification that gets triggered by the event know to invoke the notification script? Where will I call my notification script from?

 

Hi Jeff,

 

We can directly call a mail script in the notification triggered by the event, by using ${mail_script:script name}.

To your original question, in order to pass more than 2 variables in an event params, like i've mentioned above, we can pass a strigified JSON object, and then parse it back as a JSON, and then get the values from the JSON properties at the subscriber (mail script/workflow activity etc.).

If you're using a create event workflow activity, please make sure that the "current" object in the context is the same as what the event registry and the notification are using, i.e. "sc_req_item" in your case.

 

Thanks & Regards,

Rishabh Jha

Aavenir (https://www.aavenir.com/)

Thank you Rishabh Jha.

I appreciate your time.

I did not know that an email script can also be used for who is sent the email. This will come in handy.