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

Renu9
Tera Contributor

Hi @Harish KM By mistakenly the previous post was accepted. But in the run script below even the logs are executing and the branches are not going to next run script. It is getting struck there itself.Can you please guide 

Please find the screenshot

Renu9_0-1707447389878.png

Renu9_1-1707447447116.png

 

From the show workflow in RITM

Renu9_2-1707447528932.png

 

 

Hi @Renu9 your run script should look like this, tested in PDI returns result, I have 2 checkbox variables here.

HarishKM_0-1707448629855.pngHarishKM_1-1707448644203.png

I selected both variables and output

HarishKM_2-1707448670275.png

Selected single variable

Output

HarishKM_3-1707448723036.png

 

Regards
Harish

Renu9
Tera Contributor

Hi @Harish KM 

Thanks for it, but I want to keep different dynamic values for keyboard and mouse separately. So, in this case first if statement will not work right. And I am having 6 variables like keyboard, mouse, webcam, monitor, desktop, etc.

There will be multiple combinations .

 

My use case is the user can request any one of the item in those 6 or all those 6 or few of them.

For each variable it is with different dynamic values.

Hi @Renu9 you can check the value of variable dynamically as well, what type of variables are you using? share more details on the variables so that i can help you with correct code

Regards
Harish

Renu9
Tera Contributor

Hi @Harish KM 

Below are the variables

1.What kind of keyboard is needed?

2.What kind of mouse is needed?

3.What kind of webcam is needed?

4.What kind of monitor is needed?

5.What kind of laptop is needed?

 

There are few choices in all these variables. The user can request any one of these , multiple or all based on his requirement.

When keyboard is selected then the corresponding keyboard type from the consumable table if the stock is available then it has to be assigned to the requested user. For this, there is a script include. Same way for mouse, webcam, laptop, monitor ,etc

 

If keyboard is selected then I want to fetch and store value for the keyboard consumable item in a variable. This value I have to pass it in run script. So, here if else wont work because the user can request multiple items.

 

For example, if user requests for keyboard, mouse and monitor and not webcam and laptop then one item for keyboard will be assigned to user and deducted from consumable table. Same way for mouse and monitor.