How to pull the output from the Query AD activity to use in another activity

User163016
Tera Contributor

I'm working on an orchestration workflow where I have the Query AD activity set up to get the employee's manager's distinguishedname so that it can be included in the Create AD object. I have the Query Ad activity set up correctly and I can see I'm pulling back the correct distinguishedname information, the problem I'm having is getting this into a scratchpad variable to bring it forward to process in a run script that sets up the JSON for the Create AD object.

I've read a few posts on how this is done but can't seem to pull the dn from the activity. Here is the run script that I'm using after the query ad actvity. I've tried several different variations of this with no success:

var arr = JSON.parse(workflow.scratchpad.queryAD);
if(arr.length>0){
workflow.scratchpad.DN= workflow.scratchpad.queryAD;
}

How can I pull the distinguishedname from the query AD object into a variable that can be used in another activity?

4 REPLIES 4

sidkak
Tera Contributor

Did you ever get it to work. If so please share the results. I try to add the output to gs.log(data.get(14).output) but this throws me an errror.

User163016
Tera Contributor

Hi Sidkak,

I did get it figured out.  Here is the script I used in a run script activity after the Query AD, to pull the data and move it to a scratchpad variable for later use.  I've included a sanitizeResults function that was required for this specific variable

var parser = new JSON();
var obj = parser.decode(sanitizeResults(data.get(44).output));
var dn = obj.distinguishedname;

function sanitizeResults(obj) {
	obj = obj.replace(/<\/*(powershell|output)>/g, "");
	obj = obj.replace(/((^\[)|(\]$))/g, "");
	return obj;
}

workflow.scratchpad.dn=dn;

Hope this helps.

sidkak
Tera Contributor

Thanks for the response. The sanitizeresults function actually helps to get back the data. Since I am new to Service now Orchestration I have 2 questions, might be silly buy will be helpful to clear my doubts to a great extent.

1. HOw was it identified to use the sanitize function. I mean from where were you able to see and decide the expression to make the output from query AD into proper JSON Data?

2. Once we have put the data onto the scratchpad can i see that on the running workflow context or do i have to redirect each data points onto the logs.

 

User163016
Tera Contributor

Hi Sidkak,

1. In our case, we were working with the distinguished name attribute in AD and we needed the sanitized results for it to work in downstream activities.  I started to adopt the sanitize results on other output activities as well and just found that things work much better all around doing that.

 

2. If you follow the Workflow context link on the RITM you should see the scratchpad data there.  However, I also log the data points when I'm in my lower environments because it makes it easier to troubleshoot.  Once I know that I'm getting the data I need, I comment out the logs before going to production.