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

But which request sys id i need to use. It will vary everytime. I have this code in my run script.

Hi,

If you are using workflow for catalog item then you just need below logic in run script activity.

var CIList = current.variables.server_names.toString();  //replace server_names with your List collector variable name
var grCI = new GlideRecord('cmdb_ci');
grCI.addEncodedQuery('sys_idIN'+CIList);
grCI.query();
while(CIList.next()){
CIList.operational_status = 'your new value';  // use field name and value as per your requirement
CIList.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

It seems the script is correct but based on my requirement i need to have an approval on catalog task but that approval is triggering on sc_req_item table and post approval nothing is updating in the respective tables.

Hi @Poorva Bhawsar  can you please share how approval is triggered on SC Task?

If it is through workflow then you can add run script activity after approval activity.

Other wise you need to create a Business rule and use script in BR to update CI's.

The choice BR and Table is depend  on your current configuration.

 

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