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

Sayali Gurav
Tera Guru
Tera Guru

Hello @Renu9 ,

 

// Add your condition to check
if (condition) {
// Dynamic value when condition is true
var dynamicValue = "Dynamic Value 1";
} else {
// Dynamic value when condition is false
var dynamicValue = "Dynamic Value 2";
}

// Use the dynamicValue in your script
gs.info("Dynamic Value: " + dynamicValue);


Replace 'condition', "Dynamic Value 1", and "Dynamic Value 2" with your actual conditions and dynamic values. 

 

If this will helps to resolve your issue then please mark helpful and accept as solution.

 

Thanks & Regards,

Sayali Gurav

 

Hi @Sayali Gurav 

I need to put multiple if conditions in the workflow and all should point to same run script 

Can you please let me know where we can give the condition and pass the dynamic values? 

Hi @Renu9 in that case go for switch statement where you can have multiple dynamic values to pass to your run script.

Regards
Harish

Renu9
Tera Contributor

Hi @Harish KM In this case, switch shows the choices for that variable.

But in my case. If keyboard is selected as 'Ergo Keyboard 123', then run script should execute.

If mouse is selected as 'Mouse CPA1', then run script should execute. As a sample below. I want to execute all if statements. How can it be acheived. Single run script but dynamic value should be passed each time.

Renu9_0-1707407756805.png