I write the blow code in if activity in workflow. It is not working

Chandra18
Mega Sage

I want to divide if activity in three part.. OSvalue is passed the correct value but if activity not passed the way. 

I write the three conditions for this activity:

activity. result=='win10'

activity. result=='win11'

activity. result=='blank'

 

 

The code is :

 

var OSvalue = workflow.scratchpad.Operatingsystem;
gs.log('Chandra@@@@' + OSvalue);

answer = ifScript();

function ifScript() {
if (OSvalue.includes("Windows 10")) {
return 'win10';
}

if (OSvalue.includes("Windows 11")) {
return 'win11';
} else {
return 'blank';
}
}

2 REPLIES 2

Vishal Birajdar
Giga Sage

Hello @Chandra18 

 

Can you share if possible some screenshot of workflow and "if activity"

 

 

Vishal Birajdar
ServiceNow Developer

I know one thing, and that is that I know nothing.
- Socrates

Danish Bhairag2
Tera Sage
Tera Sage

Hi @Chandra18 ,

 

I think the IF activity in the workflow should return either 'yes' or 'no' in orde to move forward. Based upon yes or no u can decide what u need to do.

So ur code should look like 

var OSvalue = workflow.scratchpad.Operatingsystem;

gs.log('Chandra@@@@' + OSvalue);

 

answer = ifScript();

 

function ifScript() {

if (OSvalue.includes("Windows 10")) {

return 'yes';

}

 

if (OSvalue.includes("Windows 11")) {

return 'no';

} else {

return 'no';

}

}

 

From the above code there are 2 'no' so what u can do is u can add 1 more if to the output of no n again check only for no part of the logic.

 

Thanks,

Danish