The Zurich release has arrived! Interested in new features and functionalities? Click here for more

Query and update via Business Rule

Tony K
Kilo Sage
Kilo Sage

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();

  }

6 REPLIES 6

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


She Sull
Giga Guru

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();


}