Adding affected CI's to change request using Transform script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-25-2024 09:58 PM
Hi,
I have an import set api to create change requests.
Based on few conditions I want to add multiple Affected CI's to the Change request once its created.
I am trying to do this using the onbefore Transform script but it's not adding the CI's to Affected CI related list.
How can I achieve this?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-25-2024 10:29 PM
Hi,
Is the import creating the Change Request? Then you may want to consider using onAfter instead of onBefore. The Change Request must exist before the Affected CIs can be mapped to it.
What does your script look like?
Regards,
Niklas
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-25-2024 11:28 PM
Hi,
Yes the import API is creating the change request
I also tried it in OnAfter script:
Below is the script that I am using
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-26-2024 02:37 AM - edited 05-26-2024 02:38 AM
Hi @Jake Adams ,
Please try the below code in onAfter transform script:
(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {
var gr = new GlideRecord('table_name'); //table_name is my custom table name
gr.addEncodedQuery("cmdb_ci.operational_status = 1");
gr.query();
while (gr.next()) {
var taskCR = new GlideRecord('task_ci');
taskCR.initialize();
taskCR.task = target.sys_id;
taskCR.ci_item = gr.u_configuration_item;
taskCR.insert();
}
})(source, map, log, target);
Please mark this response as correct or helpful if it assisted you with your question.
Mark this as Helpful / Accept the Solution if this helps.