0

The method getUniqueValue() does not always return an id – TRUE or FALSE? 0 (0)

During Live Coding Happy Hour (LCHH) last week session about Decision APIs I got intrigued when Earl Duque used gr.getValue(‘sys_id’) instead of gr.getUniqueValue(), and in the comments was mentioned getUniqueValue() does not always return the sys id, so lets confirm that.

Lets take a look at the API Documentation says (here).

It says “get the primary key of the record which is usually sys_id unless otherwise specific”. Interesting, what they mean by primary key of a record? There’s a field called “Primary” that is only true for the Sys ID.

Made “PK” field as primary, did a quick GlideRecord query() and it always returned the sys id. I couldn’t prove their hypothesis – getUniqueValue is returning always the sysId. What did I miss?

It seems you can have multiple fields with primary = true (?).

var grTest = new GlideRecord('x_299742_nowjedi_example');
grTest.query();
while (grTest.next()) {
      gs.info(grTest.getUniqueValue());    
}

If you know the answer to this please drop in the comments.


Thank you,
Raf