Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

Subflow returns the wrong result when called in Workflow

Not applicable

I created a subflow so that I could call it in a legacy workflow. All it does it query whether a user is a member of an AD group. When I call it in a workflow using a script activity it returns true. Yet when I call it from a background script or directly from flow designer with the same inputs I get false which is what I am expecting because the user is not in the AD group. 

 

********Background Script*************

var inputs = {};

inputs['user'] = 'secyorkb'; // String
inputs['group'] = 'SN.03 Test Related App - SOC1'; // String
// Execute Synchronously: Run in foreground. Code snippet has access to outputs.
var result = sn_fd.FlowAPI.getRunner().subflow('global.is_user_in_group').inForeground().withInputs(inputs).run();
var outputs = result.getOutputs();

// Get Outputs:
// Note: outputs can only be retrieved when executing synchronously.
var is_member = outputs['is_member']; // True/False
gs.addInfoMessage('XX: outputs ' + is_member); ----> This returns false

 

************Subflow***************

ChrisDoernbrac_0-1716432931296.pngChrisDoernbrac_1-1716432957211.png

 

***********Workflow Script Activity*************

I hard coded the values to make sure it would definitely use the same data

 

try {
    var reqType = workflow.scratchpad.requestType; //Normal/Elevated/Service
    var adUser = 'secyorkb';
    var groupName = 'SN.03 Test Related App - SOC1';

    var inputs = {};
   
    inputs['user'] = adUser; // String
    inputs['group'] = groupName; // String
    gs.log('XX:3 inputs: ' + inputs.user + inputs.group);

    // Execute Synchronously: Run in foreground. Code snippet has access to outputs.
    var result = sn_fd.FlowAPI.getRunner().subflow('global.is_user_in_group').inForeground().withInputs(inputs).run();
    var outputs = result.getOutputs();

    // Get Outputs:
    // Note: outputs can only be retrieved when executing synchronously.
    var is_member = outputs['is_member']; // True/False
    gs.log('XX:4 outputs ' + is_member);
    workflow.scratchpad.isMember = is_member; ------->returns true

} catch (ex) {
    var message = ex.getMessage();
    gs.error(message);
}
________Logging__________
ChrisDoernbrac_2-1716433102603.png

 

What could be causing the workflow activity to return true when the other two methods return false
1 ACCEPTED SOLUTION

Not applicable

It turns out that though I was passing in a string to function it was treating it as an object for some reason. Once I added .toString() it works fine. 

View solution in original post

6 REPLIES 6

Ravi Chandra_K
Kilo Patron

Instead of putting 2 mins wait activity, try keeping the wait time in the script itself just after calling subflow.

Using gs.sleep(milliseconds). Not a best Practice but you can still try to see if it's a synchronous issue

 

Not applicable

It turns out that though I was passing in a string to function it was treating it as an object for some reason. Once I added .toString() it works fine.