How to pass dynamic values to single run script based on if condition

Renu9
Tera Contributor

Hi All,

 

I am having multiple if conditions such as if Keyboard needed is selected as Yes, then in the run script , I want to consume a keyboard record and assign to requester.

If mouse needed is selected as Yes, then in the run script , I want to consume a mouse record and assign to requester.

If Webcam needed is selected as Yes, then in the run script , I want to consume a webcam record and assign to requester.

 

So, for the keyboard, the item name is Ergo Keyboard 123, for the mouse, the item name is Mouse CPA1

 

So, I am thinking to use a single run script but pass these values from if condition to run script. How it is possible.

 

var consUtil = new Consumables();
var gr = new GlideRecord('alm_consumable');
gr.addQuery('stockroom', 'Tech distribution center'); //Tech distribution center
gr.addQuery('display_name', 'Ergo Keyboard 123');
gr.addQuery('install_status', '6'); //in stock  - state
gr.addQuery('substatus', 'available');
gr.query();
if (gr.next()) {
    gs.log("stock is available " + gr.quantity);
    workflow.scratchpad.consumable = consUtil.splitForeground('02f2114547083d94785b87d8536d43fc', 1, '10', '', '', '', '', current.request.requested_for);
 
}
else
{
task.state='2'; //work in progress
task.work_notes ='This task was closed without  an item ';
}
 
This is for keyboard , how can I pass dynamically for all items. Please guide
1 ACCEPTED SOLUTION

Hi @Renu9 in this cases, instead of while/switch, create a run script and check all the variable value and store it in different scratchpad variables/activity result and in next run script you can check these

 

if (current.variables.var_name == 'value1') {
activity.result = 'value1';
} else if (current.variables.var_name == 'value2') {
activity.result = 'value2';
}
else if (current.variables.var_name == 'value2' && current.variables.var_name == 'value1') {
activity.result = 'value3';
}

 

 

Regards
Harish

View solution in original post

14 REPLIES 14

HI @Renu9 switch statement will execute based on the choice selected, if you still want to use if, you can use. In your screen shot the 1st if statement, if keyboard is not selected then the "no" option should point to the next if statement. which you have left blank so in this case the if is not moving to next statement.

example

1st statment:

keyboard selected ? Yes --> run script

                                  No --> point to next if statement

Regards
Harish

Renu9
Tera Contributor

Hi @Harish KM 

In this case i have to run all the if statements . Because the user can request for keyboard mouse webcam etc etc. so if i keep if else condition then if keyboard satisfied it is not going to mouse or webcam part. So if else wont work

in switch case can u help me with that. Because if i use switch block it is displaying the choices in that variable . 

Hi @Renu9 switch also will execute either one. May I know your use case ? what needs to be done?

Regards
Harish

Renu9
Tera Contributor

Hi @Harish KM 

my use case is like when new user joined into the company he will be requesting for laptop keyboard mouse webcam all these items

so if he selects all these consumables then when the request is closed complete then quantity of 1 will be reduced from the consumable table

so there is a chance he selects all items right

so in this case if else is not working 

Hi @Renu9 in this cases, instead of while/switch, create a run script and check all the variable value and store it in different scratchpad variables/activity result and in next run script you can check these

 

if (current.variables.var_name == 'value1') {
activity.result = 'value1';
} else if (current.variables.var_name == 'value2') {
activity.result = 'value2';
}
else if (current.variables.var_name == 'value2' && current.variables.var_name == 'value1') {
activity.result = 'value3';
}

 

 

Regards
Harish