How to add a list of CI from Catalog variable to Affected CI related list?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-05-2020 09:13 AM
I have a list collector of CI (cmdb_ci) in my catalog. Upon submission I would like it to be added to the Affected CI related list on my RITM module. Do you have any idea how to do this? Thank you very much.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-17-2021 01:35 PM
I'm not sure if this would work on the task activity due to timing, but if the CI list collector variable is not included on the task, be sure to change the array push to
ciarr.push(current.request_item.variables.list_collector_variable_name.toString());
You also need to change the rec.task line to reference the task instead of the RITM, since you want to link the task to the affected CIs, so try this
rec.task = task.sys_id;
workflow.info('task sys_id = ' = task.sys_id.toString());
I added a log line so that you can verify if this is returning the sys_id of the task that's getting created (look in the Workflow Context, Log tab on the RITM).
If this doesn't work then you can add a Run Script after the task activity, or to see it when the task processor views the task, put a parallel path coming from the previous activity to a 10 second (or so) timer, then the Run Script. There doesn't have to be a path coming out of the Run Script. You would still need the task sys_id, so if it's captured using task.sys_id but the timing didn't work to add the affected CI script in the task activity, just add a line to the task activity to capture the sys_id in a scratchpad variable so that you can use it in another activity
workflow.scratchpad.taskid = task.sys_id.toString();
then use workflow.scratchpad.taskid in the rec.task line. If the task sys_id isn't getting captured this way, then you'll need to do a GlideRecord in the Run Script - query the sc_task table with conditions request_item = current.sys_id and short_description = whatever that task is.
I'll also mention that what we've done in this case rather than any of the above is to add a custom related list to the task form, showing the "Affected CIs Parent", so no new script was needed - but in this case the task relationship isn't there, so if you look on the CI it won't show that this Catalog Task is related to it, just the RITM, but it's a pretty clean solution if that's what you're looking for.