Change the state of CI based on a list collector field value on a catalog item

Poorva Bhawsar
Mega Sage

Hi Community,

 

I want to change the value of CI state from abc to xyz selected on the CI list collector field of a catalog item using workflow.

 

This is what i did so far.

 

var grCI = new GlideRecord('cmdb_ci');
grCI.getValue('server_name_s');
grCI.addEncodedQuery('operational_status=8');
grCI.query();
while(grCI.next()){
    grCI.setValue('operational_status',1 );
    grCI.update();
}
1 ACCEPTED SOLUTION

Hi,

Use below script:

var CIList = current.variables.server_name_s.toString();
var grCI = new GlideRecord('cmdb_ci_computer');
grCI.addEncodedQuery('sys_idIN' + CIList);
grCI.query();
while (grCI.next()) {
    grCI.operational_status = 1;
    grCI.update();
}
Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande

View solution in original post

14 REPLIES 14

Please share your variable configuration and script you have written in workflow.

 

Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande

var CIList = current.variables.server_name_s.toString();
var grCI = new GlideRecord('cmdb_ci_computer');
grCI.addEncodedQuery('sys_idIN' + CIList);
grCI.query();
while (grCI.next()) {
    grCI.operational_status = 1;
    grCI.update();
}
 
Here we go.
 
Variable name is there in script and its type is list collector.

Hi,

Use below script:

var CIList = current.variables.server_name_s.toString();
var grCI = new GlideRecord('cmdb_ci_computer');
grCI.addEncodedQuery('sys_idIN' + CIList);
grCI.query();
while (grCI.next()) {
    grCI.operational_status = 1;
    grCI.update();
}
Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande

Yeah i have updated it later and realized that i was not using gliderecord object and the table also i need to use server instead of computer.

Any update on the request sys id? What request sys id i need to use? Because it will vary request to request.