Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

Sublflow Outputs Issue

Community Alums
Not applicable

I created a subflow that I am calling via script from a legacy workflow. I am having problems saving the output values to the scratchpad and using them in another activity. 

 

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

 

try {
    var ent = workflow.scratchpad.eaEntitlements;
    gs.log("XX: ent " + ent);
    var action = workflow.scratchpad.accessAction;
    gs.log("XX: action " + action);
    var user = current.variables.user_id_for_elevated_account;
    gs.log("XX: user " + user);
        var inputs = {};
        inputs['user'] = user; // String
        inputs['group'] = ent; // String
        inputs['action'] = action; // String
               
        // Execute Synchronously: Run in foreground. Code snippet has access to outputs.
        var result = sn_fd.FlowAPI.getRunner().subflow('global.addremove_user_from_ad_group').inForeground().withInputs(inputs).run();
        var outputs = result.getOutputs();
 
        // Get Outputs:
        // Note: outputs can only be retrieved when executing synchronously.
        var success =  outputs.success; // this is a string which is either true or false
        var error = outputs.error; // String which contains an error message

        gs.log('XX: success ' + success); //logs XX: success false which is expected
        gs.log("XX: error " + error);  //XX: error Error: Invalid User Name : (Process Automation.95de9283873151107701ed3e0ebb3571; line 39) which is expected
        
        workflow.scratchpad.adsuccess = success; 
        workflow.scratchpad.aderror = error;
       
    } catch (ex) {
        var message = ex.getMessage();
        gs.error(message);
    }
 
The expectation is there are 2 outputs, both are strings, being saved to scratchpad values.
 
IF Activity using the scratchpad values*************************************************************
 
answer = ifScript();
var result = workflow.scratchpad.adsuccess;
gs.log('XX: prescript ' + result +  typeof result); //this is printing XX: prescript falsestring which is expected

function ifScript() {
    gs.log("XX: within script " + result + " " + typeof result); //This is printing XX: within script [object FlowRunnerResult] object which is not expected and causes the rest of the code to fail
 
    if (result == 'false') {
        gs.log("XX: yes1");
        return 'yes';
    }
    if(result == false){
        gs.log("XX: yes2");
        return 'yes';
    }
    if(!result){
        gs.log("XX: yes3");
        return 'yes';
    }
}
 
Why does the result value change to an object once it is used within the ifScript?  
1 ACCEPTED SOLUTION

Amit Verma
Kilo Patron
Kilo Patron

Hi @Community Alums 

 

You are not passing the result variable as a parameter to your if function. You need to tweak your script as below :

 

var result = workflow.scratchpad.adsuccess;
gs.log('XX: prescript ' + result +  typeof result); //this is printing XX: prescript falsestring which is expected

function ifScript(result) {
    gs.log("XX: within script " + result + " " + typeof result); //This is printing XX: within script [object FlowRunnerResult] object which is not expected and causes the rest of the code to fail
 
    if (result == 'false') {
        gs.log("XX: yes1");
        return 'yes';
    }
    if(result == false){
        gs.log("XX: yes2");
        return 'yes';
    }
    if(!result){
        gs.log("XX: yes3");
        return 'yes';
    }
}
answer = ifScript(result);

 

Thanks and Regards

Amit Verma


Please mark this response as correct and helpful if it assisted you with your question.

View solution in original post

3 REPLIES 3

Pratima Kalamka
Kilo Sage

Hello @Community Alums 

In the "IF Activity" script, the variable 'result' is behaving unexpectedly because it's being used without being passed as a parameter to the function 'ifScript()'.

you can pass 'result' as a parameter to the 'ifScript()' function like this:

answer = ifScript(workflow.scratchpad.adsuccess);  

and

function ifScript(result)

{

gs.log("XX: within script " + result + " " + typeof result);

}

If my answer is helpful please mark it as helpful or correct!!

 

Regards,

Pratima.k

Amit Verma
Kilo Patron
Kilo Patron

Hi @Community Alums 

 

You are not passing the result variable as a parameter to your if function. You need to tweak your script as below :

 

var result = workflow.scratchpad.adsuccess;
gs.log('XX: prescript ' + result +  typeof result); //this is printing XX: prescript falsestring which is expected

function ifScript(result) {
    gs.log("XX: within script " + result + " " + typeof result); //This is printing XX: within script [object FlowRunnerResult] object which is not expected and causes the rest of the code to fail
 
    if (result == 'false') {
        gs.log("XX: yes1");
        return 'yes';
    }
    if(result == false){
        gs.log("XX: yes2");
        return 'yes';
    }
    if(!result){
        gs.log("XX: yes3");
        return 'yes';
    }
}
answer = ifScript(result);

 

Thanks and Regards

Amit Verma


Please mark this response as correct and helpful if it assisted you with your question.

Community Alums
Not applicable

Thank you, I knew it was something simple.