Update Reference Field in Script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-12-2012 06:17 PM
Hello,
I would like to update the manufacturer field in the CMDBo to be 'Hewlett-Packard' for all records . This field is a reference field with the following information.
Table: cmdb_ci
Element: manufacturer
Type: reference
Reference: core_company
Here is my script.
var rec = new GlideRecord('cmdb_ci_computer');
rec.query();
while (rec.next()) {
rec.manufacturer = 'Hewlett-Packard'
gs.print('Record Updated ' + rec.manufacturer);
rec.update();
}
gs.print(rec.getRowCount());
Is there a way this update can be run with a script?
Thanks!
Mark Didrikson

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-12-2012 06:41 PM
You can run this from the 'Scripts - Background' module after elevating your privileges to 'security_admin'. If you want to set the name in a reference field rather than a sys_id, you'll need to use 'setDisplayValue' like this...
var rec = new GlideRecord('cmdb_ci_computer');
rec.query();
while (rec.next()) {
rec.manufacturer.setDisplayValue('Hewlett-Packard');
gs.print('Record Updated ' + rec.manufacturer);
rec.update();
}
gs.print(rec.getRowCount());
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-01-2018 08:29 AM
Great info. Thanks Mark.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-17-2018 10:31 PM
Hi mark,
I used same but the old value getting deleted but not new value updated
could u help me with that.
Regards,
Roopa
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-17-2018 10:47 PM
it worked problem with single quote 🙂
Thanks