Name-Value Pairs field - GlideRecord call to a numbered name returns undefined

kooshi
Kilo Contributor

Hello all,

I have a Name-Value Pairs field set up for a custom table. The values are as follows:

find_real_file.png

 

When I call this particular record via GlideRecord and try to get the value of the name "1", it returns undefined. Fortunately, I can get around this by creating a variable and running a JSON.parse() on the field.

BACKGROUND SCRIPT CODE

var gr = new GlideRecord("random_table");
gr.get("4d3b6e1cdba83b0085539c78db961926");

var parsed = JSON.parse(gr.local_state_values);

gs.info("Local State Values == " + gr.local_state_values);
gs.info("Local State Values [1] == " + gr.local_state_values[1]);
gs.info("Local State Values [\"1\"] == " + gr.local_state_values["1"]);
gs.info("Local State Values [\"New\"] == " + gr.local_state_values["New"]);
gs.info("Parsed variable == " + parsed);
gs.info("Parsed variable [1] == " + parsed[1]);
gs.info("Parsed variable DOT New == " + parsed.New);

RESULT

random_table: Local State Values == {"1":"random","New":"30","In Progress":"32","On Hold":"34","Resolved":"36","Closed":"38","Cancelled":"39"}
random_table: Local State Values [1] == undefined
random_table: Local State Values ["1"] == undefined
random_table: Local State Values ["New"] == 30
random_table: Parsed variable == [object Object]
random_table: Parsed variable [1] == random
random_table: Parsed variable DOT New == 30

Is this an intended behavior? I would've thought that this Name-Value Pair field type would be an object rather than a string.

Thanks!

6 REPLIES 6

sachin_namjoshi
Kilo Patron
Kilo Patron

Please use below code

 

var gr = new GlideRecord("random_table");
gr.get("4d3b6e1cdba83b0085539c78db961926");

for (var name in gr.local_state_values) {

gs.print(name + " = " + gr.local_state_values[name]);

}

 

 

Regards,

Sachin

Unfortunately, that does not work. The numbered name still appears as undefined.

random_table: 1 = undefined
random_table: New = 30
random_table: In Progress = 32
random_table: On Hold = 34
random_table: Resolved = 36
random_table: Closed = 38
random_table: Cancelled = 39

Alexey7
Mega Sage

Hi, it is intended to be like this. Object property could by any sequence of alphanumerical characters, including '_' and '$', but cannot START with a number. You can change property key to something else or use a workaround you come up with.

Hope this clarify a little bit.

 

kooshi
Kilo Contributor

Thanks for the confirmation on the intention. Just to clarify on your wording a bit, the Name part CAN start with a number as long as it is not only a number. For example, using "2a":"random" actually shows up properly if I were to run gr.local_state_values["2a"].

I will have to stick with my JSON.parse() workaround then.