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

Hello Ankur

 

Sadly this did not work. It resulted in false even though the chosen server was on the cmdb_ci_win_server table. Any suggestion as for how to debug this?

 

Thanks

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);

 

This also worked! Thank you, Ravin 🙂

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 🙂