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

patricklatella
Mega Sage

Hi Anudeep,


the answer for these variables is actually being defined in this line.



a = qa.value;



I know this because if I just put



a = "hello";



in my script:



var a ='';


var q = '';


var ind ='';


while(qa.next())


{


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



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


{


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


qq.get(qa.value);


a = qq.getDisplayValue();


}


else


{


a = 'hello';



then I get this result, and see how the variables in question return "hello".   So these are not being defined in the "if" part, they are being defined in the "else" part.



find_real_file.png


patricklatella
Mega Sage

so I just realized that it is not a problem because the table type is Data Lookup Matching Rules, it is because of the mapping elements involved.   I changed the reference fields to straight master data tables and it worked!


Glad it worked



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



Thanks


Antin