To print the value entered by the user while making catalog request, if variable type is Lookup SB.

pandeyved
Tera Contributor

Hi All,

I want to retrieve the value filled by the user while making request from any catalog.

I am able to do it also, but while printing the value of that variable whose variable type is "LookUp Select Box", it is returning the output as "null".

 Here is an example of the code snippet:
var g = new GlideRecord("sc_req_item");

g.addQuery("sys_id","12232127126736712781ysuas72");

g.query();

if(g.next())

{

var c = g.getElement(variables.choose_permission.name);

gs.info(c);

}

So if Choose Permission is of type reference then it is printing the value, what user has given.

But if Choose permission is of type  Lookup Select Box, then it is returning Null.

 

Pls guide, how I can achieve a generic a way, be it reference variable or Lookup select box, it should print in both case.

 

Thanks.

1 REPLY 1

SwarnadeepNandy
Mega Sage

Hello,

 

This is because the Lookup Select Box variable stores the value as a reference to another table, not as a string. Therefore, you need to use the getDisplayValue() method instead of the getValue() method to get the display value of the reference field.

Here is an example of how you can modify your code snippet to achieve this:

var g = new GlideRecord(“sc_req_item”);

g.addQuery(“sys_id”,“12232127126736712781ysuas72”);

g.query();

if (g.next()) {

    var c = g.getElement(variables.choose_permission.name);

    gs.info(c.getDisplayValue()); // use getDisplayValue() instead of getValue()

}

This should print the value that the user has selected in the Lookup Select Box variable.

 

Kind Regards,

Swarnadeep Nandy