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

I am doing same. Using run script after approval but first catalog task activity is there. If i didnt check the wait for completion checkbox under this activity it will not complete and in the show workflow its showing its proceeding further and completing the workflow but its not updating anything.

 

Here is the snap of my workflow.

 

PoorvaBhawsar_2-1705474430946.png

 


 

Also the approvals are getting created on ritm table instead of sc task.

 

Yes,

The workflow is running on requested Item so it will create approval on sc_req_item table not sc_task.

Is your run script activity running?

Also put some logs to check if it is finding any CI or not.

Share configuration of your list collector variable, to which table it is referring?

 

 

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 that i know but as per my requirement i want it on sc task table. Run script activity is running i checked it using show workflow. The list collector variable is referring on cmdb_ci table only.

If you want approval on sc_task then Approval Activity will not work, you need to use run script to trigger approval and wait for condition to wait until approval is processed.

 

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

This code is not working. Its not doing anything.