Help getting Query AD output from databus

apjohn2
Mega Sage

Hi everyone!

I have a workflow which is supposed to loop through users from a list collector variable and do a handful of Orch activities. I know the data being passed into the workflow is good because one of the orchestration pieces (to update an extension attribute in the AD user record) is working fine.

I'm stuck with the Query AD and subsequent If activities. I can't seem to get to the output from the databus no matter what I do. I've referred to multiple posts here but can't get anything to work.

What I need is this:

  • Query AD for the user and pull back a single attribute: extensionAttribute15
  • In a subsequent If activity, determine if the value of extensionAttribute15 is equal to "o365_Licensed_Standard" or not
  • If that is the value, return yes, else, return no.
  • Last time I ran a test I got 'undefined' for the 'ea15' variable shown below and have no idea why

I can't get this to output even when testing on a user I know has the affirmative setting.

Here's the whole script, including some commented-out lines where you can see different things I've tried. I can confirm the 'Data' tab shows "7" next to the activity output in question.

Anyone have a suggestion? (Much appreciated in advance!)

var ea15 = '';
var qry = new JSON();
qry = qry.decode(sanitizeResults(data.get(7).output));
ea15 = qry['extensionAttribute15'];
function sanitizeResults(qry) {
	qry = qry.replace(/<\/*(powershell|output)>/g, "");
	qry =qry.replace(/((^\[)|(\]$))/g, "");
	return qry;
}
gs.log('QUERY RESULTS FROM JSON DECODE DATA GET 7' + ea15);
if (ea15.indexOf('o365_Licensed_Standard') > -1) {
	answer = 'yes';
}
else {
	answer = 'no';
}

// var parser = new JSON();
// var obj = parser.decode(sanitizeResults(data.get(7).output));
// var olic = obj.extensionAttribute15;

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

// if (olic.indexOf('o365_Licensed_Standard') > -1) {
// 	answer = 'yes';
// }
// else {
// 	answer = 'no';
// }

// var queryResults = new JSON().decode(data.get(7).output);
// gs.log('QUERY RESULTS FROM JSON DECODE DATA GET 7' + queryResults);
// answer = ((queryResults.length > 0 && queryResults == 'o365_Licensed_Standard') ? 'yes' : 'no');

// if (queryResults.length > 0 && queryResults.indexOf('o365_Licensed_Standard') > -1) { answer = 'yes'; }
// else { answer = 'no'; }
1 ACCEPTED SOLUTION

apjohn2
Mega Sage

I figured it out after some more testing and tooling in the light of a new day. How I fixed it:

As I slept on it I realized I'd read others reading the output from the databus in some form of testing. I realized I could do this by going into the Custom tab in the Workflow editor > click the Query AD activity to open it > click Test Inputs > enter valid parameters and see what I get back.

When I did this I got good results.

Next I needed to figure out what kind of variable this is. So I pared it all back to basics following this KB article, logged some outputs after attempting to use array.join(), toString(), etc.

Turns out I didn't have to change anything in the Query AD activity, and below is what I ended up with in the subsequent If activity and it works! I realize the toString() bit might be superfluous but it works so I'm leaving it like this and I'm as happy as a puppy with two tails. 🙂

var ea15 = data.get(7).output;
var ea15String = ea15.toString();

if (ea15String.indexOf('o365_Licensed_Standard') > -1) {
	answer = 'yes';
}
else {
	answer = 'no';
}

View solution in original post

7 REPLIES 7

apjohn2
Mega Sage

If it helps when I add a gs.log line to record what is being set to the 'qry' variable (just before I attempt to write to the 'ea15' variable) I get this:

JSON DECODE RESULTS: [object Object]

(the log line is "gs.log('JSON DECODE RESULTS: ' + qry);"

apjohn2
Mega Sage

Also here's the Query AD activity that precedes the If activity

apjohn2
Mega Sage

I figured it out after some more testing and tooling in the light of a new day. How I fixed it:

As I slept on it I realized I'd read others reading the output from the databus in some form of testing. I realized I could do this by going into the Custom tab in the Workflow editor > click the Query AD activity to open it > click Test Inputs > enter valid parameters and see what I get back.

When I did this I got good results.

Next I needed to figure out what kind of variable this is. So I pared it all back to basics following this KB article, logged some outputs after attempting to use array.join(), toString(), etc.

Turns out I didn't have to change anything in the Query AD activity, and below is what I ended up with in the subsequent If activity and it works! I realize the toString() bit might be superfluous but it works so I'm leaving it like this and I'm as happy as a puppy with two tails. 🙂

var ea15 = data.get(7).output;
var ea15String = ea15.toString();

if (ea15String.indexOf('o365_Licensed_Standard') > -1) {
	answer = 'yes';
}
else {
	answer = 'no';
}

Hey Aaron,

I am trying to do the same, but I actually need to use the samaccountname attribute that is provided in my Query AD databus output.  I have tried everything under the sun (including tons of research from the community) and I cannot get that attribute value out into it's own scratchpad variable.  Were you ever able to actually get your extensionattribute15 value out of the databus output JSON?

Thanks in advance!