Help with script: How to build a JSON object in a script include and then consume the returned data in a workflow activity?

patricklatella
Mega Sage

Hi community,

I've got a workflow run script activity that is calling a script include, passing it a couple values, and then I need the script include to pass back 2 values from a GlideRecord.  To do this I'm trying to build a JSON object to handle the 2 values being passed back to the workflow.  I'm not sure if my JSON object script is correct, and as well I'm not sure what the script needs to be in the workflow activity to consume the returned data.  Any help would be great, thanks!

Here's the script include script...not if sure this is correct:

var gr = new GlideRecord('u_ad_group_lookup');
gr.addQuery('u_user_ad_domain',adDomain);
gr.addQuery('u_application',application);
gr.query();

if(gr.next()){

var json = new JSON();
var object = {
'adGroup' : gr.getValue('u_ad_group'), //first value I need to pass back
'adDomain' : gr.getValue('u_group_ad_domain')  //second value I need to pass back
};
var data = json.encode(object);
gs.info('returned data is '+data);
return data;

And here's the workflow script...quite sure this is not correct:

var application = workflow.scratchpad.application; //first parameter to pass to script include
var userDomain = workflow.scratchpad.user_domain; //second parameter to pass to script include
var obj = new u_ActiveDirectoryGroup_lookup();  //name of my script include
var returnedData = obj.GetUserADGroup(userDomain, application);  //name of my function with passed values
var adGroup = returnedData.adGroup; //first value I'm trying to receive from script include
var adDomain = returnedData.adDomain; //second value I'm trying to receive from script include

 

 

 

1 ACCEPTED SOLUTION

Hi,

Use  this:

var returnedData = obj.GetUserADGroup(userDomain, application);

var obj = JSON.parse(returnedData);

then use obj.adDomain

 

Thanks,
Ashutosh

View solution in original post

6 REPLIES 6

Hi,

Use  this:

var returnedData = obj.GetUserADGroup(userDomain, application);

var obj = JSON.parse(returnedData);

then use obj.adDomain

 

Thanks,
Ashutosh

Thanks...that's it!  I changed "obj" since I already had that var defined in my script...but otherwise works perfectly!  thanks Ashutosh!