adding an IF statement that handles the return value if it's a sys_id?

patricklatella
Mega Sage

hi all,

I've got a GlideRecord that is retrieving the variables and values from a record.   However one type of variable on the record is a reference to a table that extends the Data Lookup Matcher Rules table, and for those variables it is returning the sys_id.   I need it to return the actual entry for the field.   I'm thinking I need an IF statement in my script to check for this particular type of variable, and then to return the display value, not the sys_id.

Any help would be great!

The script below is returning the screen shot below that.   Those sys_id values are the variable that are references to a table extending the Data Lookup Matcher Rules table.

var qa = new GlideRecord('question_answer');

qa.addQuery('table_sys_id', current.sys_id);

qa.orderBy('order');

qa.query();

var a ='';

var q = '';

var ind ='';

while(qa.next())

{

q = qa.question.getDisplayValue()+'';

if (qa.question.reference!='')

{

var qq = new GlideRecord(qa.question.reference);

qq.get(qa.value);

a = qq.getDisplayValue();

}

else

{

a = qa.value;

}

find_real_file.png

12 REPLIES 12

Hello Patrick,



Here is the updated code.


var qa = new GlideRecord('question_answer');


qa.addQuery('table_sys_id', 'c286d61347c12200e0ef563dbb9a71df');


qa.orderBy('order');


qa.query();



var a ='';


var q = '';


var ind ='';


while(qa.next())


{


q = qa.question.reference.getDisplayValue();



if(q == '')


{


a = qa.value;



}




}











Hi Pradeep, with your script it's returning this:



find_real_file.png


The following lines should be enough.



var qa = new GlideRecord('question_answer');


qa.addQuery('table_sys_id', current.sys_id);


qa.orderBy('order');


qa.query();



var a ='';


var q = '';


var ind ='';


while(qa.next())


{


q = qa.question.getDisplayValue()+'';




a = qa.question.reference.getDisplayValue();




Hope this helps. Mark the answer as correct/helpful based on impact.




Thanks


Antin


Hi Antin,


your script returned only the 3 variables that are reference variables (that are not references to this particular variable in question that's causing the issue, the 6 variables you see in my first screen shot that are referencing a table that is extended from the Data Lookup Matcher Rules table.   It seems to definitely have something to do with variables that are referencing that table (or a table extended from that table rather) that have the issue with the script.  



find_real_file.png


Hi Patrick,



Just curious to know what is the value you are seeing when you print out the name instead of the displayValue() as name is selected as the display value, are you seeing what you expect when you printout or log the name field



if (qa.question.reference!='')


{


var qq = new GlideRecord(qa.question.reference);


qq.get(qa.value);


gs.log("qq.name = " + qq.name); //???


}