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

Kalaiarasan Pus
Giga Sage

try this after the task update...




var updateCI = task.cmdb_ci.getRefRecord();


updateCI.setForceUpdate(true);


updateCI.update();



info : http://wiki.servicenow.com/index.php?title=GlideRecord#setForceUpdate


Hi Kalai



Thank you for the code snippet. How can I be sure that those 3 lines of code are executed "after the task update"?


I placed it in the "Advanced script" part of the Activity Properties: Catalog Task. But I think the task gets created after that script has run?



Regards


Let's see... Let's try adding this in a business rule .. preferably a after insert business rule that is defined on catalog task....



var updateCI = current.cmdb_ci.getRefRecord();


updateCI.setForceUpdate(true);


updateCI.update();



Note : Putting condition on the business rule so that it works only for task's you need


sumeet_n
Kilo Guru

Hi Gian,



In the workflow, how about below series of activites:



[create a task] -> [create cmdb_ci_ip_phone record] -> [script block to update task.cmdb_ci in sc_task created]



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.


- sys_updated_on will   not have new value unless you do some changes to the record before updating.