How to make a workflow IF condition that looks at chosen CI's table?

Jens Mogensen
Kilo Guru

Hi everyone

 

I have a workflow (for change requests) that needs to have an IF condition that is triggered by the operating system of the server chosen as Configuration Item (cmdb_ci) on the change form. For instance, it should evaluate to TRUE if the server is running Windows.

 

No matter what I try, I can't get it to evaluate to "true". I've tried scripts that look at whether the operating system field contains the word "Windows". I've also tried a script that looks at whether the CI is on the cmdb_win_server table but still, it results in a "false" even though the chosen server/CI clearly is on that table. Example:

 
Skærmbillede 2025-05-19 kl. 16.10.12.png

 
What am I doing wrong?

2 ACCEPTED SOLUTIONS

Ravin Ch
Kilo Expert

Hi @Jens Mogensen ,

 

Please try this script:

 

(function executeCondition(current) {

if (!current.cmdb_ci) {
return false;
}


var ci = current.cmdb_ci.getRefRecord();


if (ci && ci.instanceOf('cmdb_ci_win_server')) {
return true;
}

return false;

})(current);

 

View solution in original post

Jens Mogensen
Kilo Guru

I found a solution. I used this script in stead:

//current.cmdb_ci.model_id.name.toString().indexOf("Windows") > -1

 

It checks whether the model_id value of the chosen CI contains the word Windows. Not as sophisticated as looking at which table the CI was on, but that seemed to be part of the issue I am guessing. Model_id was a field present on the whole cmdb_ci table while the other scripts had to take the value of cmdb_ci and then find out which table it was on. I would have thought that this was possible but apparently not.

Regardless, this gives me the exact same result I was looking for so it's all good. Thank you for the suggestions 🙂

View solution in original post

8 REPLIES 8

Ankur Bawiskar
Tera Patron
Tera Patron

@Jens Mogensen 

you can use this in IF script

var ci = current.cmdb_ci.sys_class_name;
if (ci == 'cmdb_ci_win_server') {
    // it's windows server
} else {
    // it's not
}

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@Jens Mogensen 

Hope you are doing good.

Did my reply answer your question?

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

I will test it at once and get back to you. Thank you 🙂

@Jens Mogensen 

Sure, do mark my response as correct if it helped.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader