GlideRecord Pushes same value to an array

Yanal
Giga Guru

Hello Everyone!

I have a workflow on the case table that runs a script, I have a GlideRecord in that script that checks the values entered in a MRVS(Multi Row Variable Set)

find_real_file.png

If I enter two values, the warn result would show the right values I entered

But when I show the rows array in a warn it will show just one value duplicated twice.

Any Idea why that happens ?

find_real_file.png

Thanks a bunch

1 ACCEPTED SOLUTION

Sebastian R_
Kilo Sage

instead of gr.value you have to use gr.getValue('value') or gr.value.toString().

gr.value returns an object which is used in JavaScript by Reference. Therefore your record always includes a reference to the same object.

View solution in original post

4 REPLIES 4

Aniket Sawant
Mega Expert

Hi,

please write "rows.push(gr.value)"

outside while loop.

var gr = new GlideRecord("sc_multi_row_question_answer");
gr.addQuery("parent_id",current.sys_id);
gr.query();
while(gr.next())
{
gs.warn(gr.value);

}

rows.push(gr.value);

Please mark correct or helpful based on the impact.

Regards,

Aniket Sawant

I have tried that it only showed the first value entered.

 

Sebastian R_
Kilo Sage

instead of gr.value you have to use gr.getValue('value') or gr.value.toString().

gr.value returns an object which is used in JavaScript by Reference. Therefore your record always includes a reference to the same object.

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

use either toString() or getValue()

example below

rows.push(gr.value.toString())

OR

rows.push(gr.getValue('value'));

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader