GlideRecord GetDisplayValue in addquery
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-14-2020 08:38 AM
I am importing some records to the cmdb, and running a onafter script to check if the manufacturer and model exists or doesnt exist and then creating those values (in those tables), then updating those values on the cmdb record.
What I want to ask is can I do a gliderecord query where the getdisplayvalue is part of the addquery? Not part of the query result, part of the query...Because I have two fields that I want to query at the same time in the product model table, manufacturer and the model (the manufacturer and model are supplied in a spreadsheet as part of an import through a transform map).
**Note - selecting "create" on the transform map wont work, because manufacturer and model need to be pushed to product model table so I am using this script.
Portion of the script:
function productmodel_update(){
var grq = new GlideRecord('cmdb_ci_computer');
grq.addQuery('manufacturer', '=', source.u_manufacturer);
grq.addQuery('name','=', source.u_model)(;
grq.query();
Thanks
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-14-2020 08:56 AM
Generally getDisplayValue() used to get the reference field front-end value .
eg:
var gr = new GlideRecord('sys_user');
gr.get(gs.getUserID());
var gr1 = new GlideRecord('incident');
gr1.addQuery('department.name',gr.getDisplayValue('department'));
gr1.query();
gs.print(gr1.getRowCount());
If you will add more example then we can guide you in right direction.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-14-2020 09:33 AM
Thanks. But how do I add into this line how to search for my source.u_department_name?
I need to do something like below but where I search department name with my source field
gr1.addQuery('department.name',gr.getDisplayValue('department'));

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-14-2020 09:36 AM
why you need getDisplayValue() generally in source table we have string type field which store string not reference value so i am still confuse why you need getDisplayValue()
can you add some screenshot with detail example of your use case ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-14-2020 09:52 AM
- Im loading data through spreadhseet and transform map to a target cmdb table
- Running a script to check if manufacturer and model exist and if not create
- Then I do a lookup against the cmdb table I am loading into and update those records with the manufacturer and model - the manufacturer field is updating fine on the cmdb record, no issue there
- As for the model, the manufacturer field on the model record is a reference field, the name field is a string.
- I want to take the source.u_manufacturer and the source.u_model and use both to do a query against the model table to see if that record exists.
- So i wanted to use both fields in an addquery each and query the product model table, if I get a result, i will return the sysid and use that to update the cmdb record with that model, the sysid going into the model_id field
- Does that make sense?
- Screenshot of product model