Update task.cmdb_ci after Catalog Task creation

gldecurtins
Mega Expert

Hi all

 

I have got the following workflow activities in place:

  1. Run Script: Create Configuration Item in cmdb_ci_ip_phone and save sys_id of inserted record to the workflow's scratchpad
  2. Catalog Task: Update internal phone book. The task has got task.cmdb_ci set to the sys_id of the Configuration Item created in step 1.

 

I would like to update the cmdb_ci_ip_phone record after the Catalog Task has been created (sys_updated_on of cmdb_ci_ip_phone should be newer than sys_created_on of sc_task).

 

- How can I do so? The Catalog Task waits until it has been set to inactive.

- I did already try to update cmdb_ci_ip_phone in the advanced script part using GlideRecord, but cmdb_ci_ip_phone.sys_updated_on is not always newer than sc_task.sys_created_on.

- Can I somehow add an event, which triggers an update of the cmdb_ci_ip_phone?

 

Regards

-Luca.

 

PS: I do want to have the cmdb_ci_ip_phone.sys_updated_on newer than sc_task.sys_created_on, because we do sync our tables to an internal database. We have to apply a rule so that we can be sure that the sc_task is not pointing to an outdated version of cmdb_ci_ip_phone.

1 ACCEPTED SOLUTION

gldecurtins
Mega Expert

I've found a solution to solve my issue. With the script below the previsously created CI entry will have an sys_updated_on which is later than the sys_created_on of the Catalog Task:



var updateCI = task.cmdb_ci.getRefRecord();


updateCI.autoSysFields(false);


updateCI.sys_updated_on = gs.minutesAgo(-1);


updateCI.comments = current.number.toString();


updateCI.update();



I've pasted this code to the Advanced script section. The autoSysFields(false) will take care, that the sys_ fields does not get updated automatically.



Regards


-Luca.


View solution in original post

8 REPLIES 8

Hi Sumeet



I can't change my workflow without a lot of effort. The task has to wait until it's completed as I do evaluate the result:


Workflow.PNG


I could set the Catalog Task to not wait until completion, but then I would have to re-factor the error handling of the Catalog Task.



Regards


-Luca.


So, in the "Run Script: Set status of record to Deployed", you are setting the status of cmdb_ci_ip_phone record which is created in "Run Script: Create Record".... and still it is not changing the sys_updated_on value in cmdb_ci_ip_phone record?



Is my understanding correct?


Hi Sumeet



No, this does work as expected. The sys_updated_on is set correctly there.


I do want the following timings:


0s: Create CI: cmdb_ci.sys_created_on = 0s, cmdb_ci.sys_updated_on = 0s


1s: Create Task: sc_task.sys_created_on = 1s, sc_task.sys_created_on = 1s, cmdb_ci.sys_updated_on = >1s



I've found a solution to do this.



Regards


-Luca.


gldecurtins
Mega Expert

I've found a solution to solve my issue. With the script below the previsously created CI entry will have an sys_updated_on which is later than the sys_created_on of the Catalog Task:



var updateCI = task.cmdb_ci.getRefRecord();


updateCI.autoSysFields(false);


updateCI.sys_updated_on = gs.minutesAgo(-1);


updateCI.comments = current.number.toString();


updateCI.update();



I've pasted this code to the Advanced script section. The autoSysFields(false) will take care, that the sys_ fields does not get updated automatically.



Regards


-Luca.