Check variable value in a If condition on the request table workflow

mohammedunwala
Giga Contributor

Hi,

I have a Yes/No variable 'v_manager_approval' which is a part of a variable set used across all of my catalog items. I have Requested For Manager Approval on Request level. Requirement is whenever the value on my variable is Yes it should go for approval if the value on 'v_manager_approval' variable is No it should skip the approval.

To accomplish this: I have an if condition in the workflow and using the following script:

var cat = new GlideRecord('sc_req_item');

cat.addQuery('variables', current.variables.v_manager_approval);

cat.query();

while (cat.next()){

  if (cat =='No') {

  return 'yes';

  }

}

return 'no';

Unfortunately, the script is not working and is currently sending all catalog items for manager approval. What am i doing wrong?

Any help would be appreciated.

Thanks,

Mohammed

5 REPLIES 5

karthik73
Mega Guru

Hi Mohammed,



Assuming the workflow is running on the request (sc_req_item) table, i don't think you need the Gliderecord, you should be able to do a compare with current.variables alone.



try this way



if (current.variables.v_manager_approval == 'no')


Hi Karthik,



The workflow is running on sc_request table. That means i need a glide record, right?



Can you help me out with the script?



Thanks,


Ah, i get. Try with the script below.



var gr = new GlideRecord('sc_req_item');


gr.addQuery('request.number',<request number>);


gr.query();


while(gr.next()){


if( gr.variables.v_manager_approval == "No" ){


<do something>


}


}


Why do I have to hardcode the request number? I want to keep it dynamic. Makes sense?



Thanks,


Mohammed