If variable type is LookUp select box, then how to print the value filled by user in catalog request

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.

3 REPLIES 3

SwarnadeepNandy
Mega Sage

Hello @pandeyved ,

 

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

 

Sohail Khilji
Kilo Patron
Kilo Patron

using just gs.info(c); will not print the variable value rather you use getDisplayValue() to print it.

 

eg: replace gs.info(c); with below line.

gs.info(c.getDisplayValue);

 


☑️ Please mark responses as HELPFUL or ACCEPT SOLUTION to assist future users in finding the right solution....

LinkedIn - Lets Connect

Sourabh Akiwate
Giga Expert

Hello @pandeyved 

 

If you are using Type as a "Look up select box" then in the 'Lookp value field' we can select the field name which we can use it as backend value in script. And, in the field 'Lookup label field(s)' we can select the field which we want to show on form.

Also, please follow below script:

 

SourabhAkiwate_1-1691952468056.png

SourabhAkiwate_2-1691952595824.png

NOTE: in the above script sys ID should be same

 

If you find this answer useful please mark my answer correct and helpful.

Thanks