MultiRow Variable set is not populating the values in the variable

ponmudi
Tera Contributor

i am developing a catalog client script to populate values based on gliderecord query against the snow table. It could print the value as expected. In console.

However, when i try to setValue based on the result, its not updating in the MRVS. 

My Varaibale set name is ServerNameListPopulate
My Variable set internal name is servernamelistpopulate

My variable name is sys_id, its a reference type to the system table (cmdb_ci_win_server)

My Catalog client script

function checkServer(gr2) {

while (gr2.next()) {
//console.log("server :" + gr2.child);
var gr3 = new GlideRecord('cmdb_ci_win_server');
gr3.addQuery('sys_id', gr2.child);
gr3.query(getServerfqdn);
}

function getServerfqdn(gr3) {
var output = [];
while (gr3.next()) {
console.log("server :" + gr3.fqdn);
var obj = {};
obj["sys_id"] = gr3.fqdn;
output.push(obj);

}
console.log("output is: " + JSON.stringify(output));
console.log("output is: " + JSON.stringify(obj));
g_form.setValue('servernamelistpopulate', JSON.stringify(output));

}
}



What's the mistake here? Loop? or anything else? like set value?

6 REPLIES 6

Abhijit4
Mega Sage

While setting object, try below line in your code :

 

obj={"sys_id":gr3.fqdn};

 

Also It is not best practice to use GlideRecord in client script, instead try using GlideAjax to get data.

 

Please mark as Correct or Helpful based on impact.

By marking my response as correct or helpful, you contribute to helping future readers with similar issues.
Regards,
Abhijit
ServiceNow MVP

ponmudi
Tera Contributor

i changed based on the alternate way that you shared. its not helping.
i heard, we need to pass the sys id of the record in MRVS to get it populated there.
if that is the case, how i can glide to get the sysid of the record and pass FQDN to MRVS. Would you please help on that, based on my code.

Brad Bowman
Kilo Patron
Kilo Patron

I would recommend not naming variables reserved/key field names like 'sys_id' to prevent confusion and unexpected results.  If you are getting all of the correct log values throughout this script, try adding .toString() to the object assignment so you are certain to get the string value.

obj["sys_id"] = gr3.fqdn.toString();

Are you storing a sys_id in the text field fqdn?  If so, why?  If not, then the MRVS variable type needs to be changed as this will be looking for a sys_id of a record on the win_server table. 

Here's an alternate object assigning syntax:

var output = [];
while (gr3.next()) {
    console.log("server :" + gr3.fqdn); 
    output.push({"sys_id" : gr3.fqdn.toString()});
}

 

i changed based on the alternate way that you shared. its not helping.
i heard, we need to pass the sys id of the record in MRVS to get it populated there.
if that is the case, how i can glide to get the sysid of the record and pass FQDN to MRVS. Would you please help on that, based on my code.