Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
var updatedSysIds = [];
var notUpdatedSysIds = [];

var gr = new GlideRecord('< table_name >');
gr.addQuery('< query condition >');
gr.query();

while (gr.next()) {

var relCi = new GlideRecord('cmdb_rel_ci');
relCi.addQuery('child', gr.sys_id);
relCi.addQuery('parent.sys_class_name', '< backend name of the table to which the reference field is referred to >');
relCi.query();

if (relCi.next()) {
// Update the reference field with the referenced table's sys_id
gr.< reference field backend name > = relCi.parent.sys_id;
gr.setWorkflow(false);
gr.update();
updatedSysIds.push(gr.sys_id.toString()); // Add to updated list
}
else {
notUpdatedSysIds.push(gr.sys_id.toString()); // Add to not updated list
}
}

// Print the sys_ids of the records updated and not updated
gs.print("Updated records sys_ids: " + updatedSysIds.join(', '));
gs.print("Not updated records sys_ids: " + notUpdatedSysIds.join(', '));
2 changes: 2 additions & 0 deletions Background Scripts/readME.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
In this piece of code, we are querying a table for some records and then updating a particular reference field's value of those records to the value of the specific parent class to which it has a cmdb_rel_ci relationship.
We are also printing the sys_ids pf the records which would be updated and the ones that would be skipped.
Loading