how to achieve "if field value is NOT null" logic branching in flow designer?

AndrewB1
Tera Contributor

To make a long story short, I've tried a number of things and am unable to create and IF branch in a flow that runs only when a task field is NOT empty.  The goal is to send out approvals to the individuals in an "additional_approvers" field if that field contains values, otherwise the flow ends.  Is there any reason why simply using the IF conditional set to "is not" then leaving the next field blank shouldn't work for this?

Alternatively, would it be reasonable to create a custom action that might return T/F based on whether input is null, as a workaround?

1 ACCEPTED SOLUTION

Purna1
Giga Expert


In old version, We are using "is not" from filter and leave as black but in latest version(Quebec) we have OOTB functions.
ServiceNow has provided OOTB box utilities functions. We can call the function to check the data pill is blank or null value.
Please find the reference screenshot.find_real_file.png

 

For more information. Please refer below link

https://docs.servicenow.com/bundle/quebec-servicenow-platform/page/administer/flow-designer/reference/utilities-transform-functions.html#d1097001e249

 

 

View solution in original post

10 REPLIES 10

Chuck Tomasi
Tera Patron

I get where you're coming from on your requirement. You may be over thinking this.

Why not pass the list of additional_approvers to the approvals whether it's empty or not? Let the next action figure out if it needs to send info or not?

Alternatively, you could create a simple action that takes a field and returns a true/false "if is empty"

Let me know if I'm not understanding the requirement entirely.

Hi Chuck, thanks for thinking about this.  Yes, I think for our purposes right now we will just do as you suggest and pass the approvers even if it's empty.  The case where there are none really is not of concern anyways since those would be applications that the HR caseworker closes prior to this stage anyway.  So I don't strictly need to do this flow control based on if the variable exists.

Regarding creating a custom action to return T/F based on whether the input was null, yes I tried it once the default IF ('x' is not) ______ approach seemed to fail but the behavior there was curious.  I tried it this way (tried to design to accommodate various "falsy" objects since it's not clear what exactly gets into the JS environment for execution):

(function execute(inputs, outputs) {
  	
  	if (!inputs.approvers){
    	outputs.out1 = false;
    } else {
      outputs.out1 = true;
    }
})(inputs, outputs);

The action works in the action testing environment and returned T/F as expected whether input was left blank or not, but when the action was put into the context of the flow it returned as T in all cases as if the value was never missing/empty.

It's like the empty value is still being passed into the action as some kind of object?

What data type is inputs.approvers in your action?

The field is a list collector referencing sys_user where one can select multiple users.  In the custom event, I tried a couple of things but I think mostly was testing it with the data type set to string, thinking it may not be critical since I just want to check "if exists", but perhaps it must be more properly matched to the data type of the field on the glide/DB side?