Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

If condition to check if manager is null not working

Brun
Mega Expert

Hello,

 

I'm trying to create a workflow if condition to check if the requested_for.manager field is empty. I used the following script, but it's not working:

  answer = ifScript();




  function ifScript() {


        if (current.requested_for.manager != '') {


              return 'yes';


        }


        return 'no';


  }

 

The goal is to branch out and cancel the request before manager approval if the user's manager field is empty.

 

Thank you!

1 ACCEPTED SOLUTION

Kieran Anson
Kilo Patron

Is this flow running on the sc_req_item or sc_request table? If the requested_for is the name of a catalog item variable you need to use current.variables.requested_for

 answer = ifScript();




  function ifScript() {


        if (gs.nil(current.variables.requested_for.manager)) {
         //if empty.

              return 'yes';


        }


        return 'no';


  }

View solution in original post

3 REPLIES 3

Kieran Anson
Kilo Patron

Is this flow running on the sc_req_item or sc_request table? If the requested_for is the name of a catalog item variable you need to use current.variables.requested_for

 answer = ifScript();




  function ifScript() {


        if (gs.nil(current.variables.requested_for.manager)) {
         //if empty.

              return 'yes';


        }


        return 'no';


  }

Thank you, Kieran! This worked out great. 

This worked great for me as well. I was needing to do something very similar and once I used the API gs.nil, it worked perfectly. I've been trying other scripting with == null but it was not working.

I was not aware about gs.nil so thanks for this.

I'm not strong in javascript so I'll remember to use this one when null values need to be determined.

Brandon