.

Kadasiddeshwar
Tera Contributor
 
5 REPLIES 5

Azhar T
Tera Contributor

@Kadasiddeshwar  

If multiple records are found then you can glide the list of records using next()

get(Object name, Object value)

Returns the specified record in the current GlideRecord object.

This method accepts either one or two parameters. If only a single parameter is passed in, the method assumes that it is the sys_id of the desired record. If not found, it then tries to match the value against the display value. If two parameters are passed in, the first is the name of the column within the GlideRecord to search. The second is the value to search for. If multiple records are found, use next() to access the additional records.


https://developer.servicenow.com/dev.do#!/reference/api/yokohama/server/no-namespace/c_GlideRecordSc...


Please mark as complete if I have answered your question

 

Mark Manders
Mega Patron

The get() method is designed to retrieve a record by its sysid. Because category is not a unique key and 'inquiry' is not a valid sys_id, you will probably get an 'undefined' number, or maybe a random incident. 

Why would you want to use it like this? What is your business requirement that this script should be used?


Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark

Chaitanya ILCR
Kilo Patron

Hi @Kadasiddeshwar  ,

 

looks like

when you are querying records with get 

it will filter the records with the query and  order the records using the same field from a to z (in this case it's category) and return the first record

 

ChaitanyaILCR_0-1749126399044.png

ChaitanyaILCR_4-1749126578626.png

 

example 2

get using priority

ChaitanyaILCR_2-1749126486463.png

ChaitanyaILCR_3-1749126529633.png

 

 

Please mark my answer as helpful/correct if it resolves your query.

Regards,
Chaitanya

 

Robbie
Kilo Patron
Kilo Patron

Hi @Kadasiddeshwar ,

 

To answer your question specifically, when multiple records match the .get() method query, the first matching record (as determined by the database engine) is returned. 

 

Please note, It is non deterministic meaning the order is not guaranteed or applied. Specifically, sys_updated_on or sys_created_on are not applied.

For reference and context - the .get() method was introduced and was designed to use as a 'short hand' if you like and return a specific record in the GlideRecord object.

See the following SN developer docs and API reference: https://developer.servicenow.com/dev.do#!/reference/api/yokohama/server/no-namespace/c_GlideRecordSc...

 

To help others (and for me to gain recognition for my efforts), please mark this response correct by clicking on Accept as Solution and/or Kudos.


Thanks, Robbie