Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

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

athm
Tera Guru

Hi Patrick,



I ran your script and looks like its working as expected.


Could you verify the table the variable is referring to has a display value set to the field you are expecting, because if no value is set then sys_id would be used as the table's display value.



Hope this helps Patrick.


Hi Anudeep,


thanks for the reply.   I believe it is setup correctly with the display.   For example this is the table the variable for "Sales Organization" in my original screenshot is a reference to.   Sys_id is not the display variable.



find_real_file.png


Hi Patrick,



You dont have to make another query to get the display value.



qa.question.reference.getDisplayValue();       - This should get you the display value.



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



Thanks


Antin


thanks Antin,


so did I add that in the correct spot?   See below, still got the sys_ids for those specific variables...notice that the other ones work fine.



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.getDisplayValue());


qq.get(qa.value);


a = qq.getDisplayValue();


}


else


{


a = qa.value;





find_real_file.png