Need to update reference field by using background script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-07-2024 02:59 AM
Hi Team,
I have a field called location in cmdb_ci table which is OOTB. I have created a custom table and create a field in cmdb_ci referencing to custom table. Based on the OOTB location field need to update custom reference field in servicenow. How we can achieve through background script in servicenow
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-07-2024 03:06 AM
Hi @Arun91 If i understand you want to update location value in your custom table based on cmdb location value?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-07-2024 03:15 AM
For Example cmdb_ci table location field is having value xyz.
Custom table is xyz and field name is ddd. In cmdb_ci table location name is GGG then the custom table field should populate YYY.
How we can achieve this.
Note: Two tables have different data we no need to copy the same data to another field.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-07-2024 03:24 AM
HI @Arun91 ,
Please use below background script to achieve the same:
var gr = new GlideRecord('cmdb_ci'); // Replace for which table of CMDB you want to do this for
gr.addEncodedQuery('locationISNOTEMPTY');
gr.query();
while(gr.next()){
gr.u_location = gr.location; //This wll copy from OOTB location to your custom attribute
gr.setWorkflow(false);
gr.update();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-07-2024 03:25 AM
Also, would like to mention that technically you can achieve your requirement using the script which I have shared above, but why are you maintaining a custom table for location and why can't OOTB location can be leveraged? Just curious?
This is going to add technical maintenance debt on your platform with every upgrade you do.