Query and update via Business Rule
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-02-2017 12:40 PM
I wrote the following business rule which should upon insert take the part number from the current record and search against a specific part table number, then update two fields if a match is found.
This currently is not working, I'm unsure how to capture the current value to search against the part number table.
// queries the part number table
var target = new GlideRecord('u_supplier_quality_part_numbers');
target.addQuery('u_part_number', current.u_part_number);
target.query();
if (target.next()) {
target.u_drawing_number = current.u_drawing_number;
target.u_drawing_revision = current.u_drawing_revision;
target.update();
}
If I hard code in values, the business rule updates fine.
// queries the part number table
var target = new GlideRecord('u_supplier_quality_part_numbers');
target.addQuery('u_part_number', '12345');
target.query();
if (target.next()) {
target.u_drawing_number = '5555';
target.u_drawing_revision = '1355475';
target.update();
}
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-02-2017 02:28 PM
Hello Anthony,
Yes, it will work. current.getValue('u_part_number') will return the sys_id as this is a reference field whereas getDisplayValue will return the display value of the reference field.
More info here.
http://wiki.servicenow.com/index.php?title=GlideRecord#getDisplayValue

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-02-2017 12:46 PM
I usually make my current values a variable, you can try:
// queries the part number table
var target = new GlideRecord('u_supplier_quality_part_numbers');
var pn = current.u_part_number;
var dn = current.u_drawing_number;
var dr = current.u_drawing_revision;
target.addQuery('u_part_number', pn);
target.query();
if (target.next()) {
target.u_drawing_number = dn;
target.u_drawing_revision = dr;
target.update();
}