Want to call a System Property in a workflow

Jyoti36
Mega Expert

Hi there,

I have created a system property : ab.provision.workflow, type : true/false

I want to put an 'if condition' in workflow to check if this system property's value is true and current requester is from some abc company then fire the next sc task.

Can anyone please share the conditions, how can i achieve this?

Thanks!

1 ACCEPTED SOLUTION

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hi Jyo,



Here you go. Untested code.


answer = ifScript();    


function ifScript() {


  var prop =   gs.getProperty('ab.provision.workflow');


var comp = current.u_requestor.company.getDisplayValue(); //I am assuming u_requestor is the field company name


//var comp = current.variables.VARIBALENAME.getDisplayValue(); //for catalog variables


if(prop == 'true' && comp == 'company name')


  {    


            return 'yes';    


          }    


          return 'no';    


  }    


View solution in original post

9 REPLIES 9

Jim Coyne
Kilo Patron

Seeing as you are using a property anyways, you might want to consider creating a new one with the sys_id of the Company record instead of using a hard-coded string with the company name.   Company names can change, but the sys_id will remain the same.


Jim - I am doing what you recommended - I have a system property that containes 3 sys_ids.   I want to compare the value of a variable in the catalog item to what is in the system property - if the variable matches any of the 3 sys_id's in the system property, it should return true. That is the only comparison I am making.


How would that script look? Below is what I have but I don't know how to write the statement compare the sys_id of the value in the variable to the string of sys_ids in the property.



answer = ifScript();        


function ifScript() {  


  var legalprop =   gs.getProperty('eu_spr_approval_legalentity');   //


  var ent   = current.variables.acx_fap_legal_ent.sys_id(); //


if(legalprop == ent)  


  {        


            return 'yes';        


          }        


          return 'no';        


  }      


This should work (untested):



answer = (function(){


      if (gs.getProperty("eu_spr_approval_legalentity").indexOf(current.variables.acx_fap_legal_ent.toString()) > -1){


              return "yes";


      } else{


              return "no";


      }


})();



The indexOf method is checking to see if the sys_id of the variable is within the property string.   It will return the position of the first occurrence of the sys_id or -1 if it is not found.



The code is assuming there are values in both the property and the variable.   You could add some validation for that.


Worked perfectly!   and thank you for the explanation!


You are welcome.