Join us Dec. 16 for The Community Hour, our first global virtual User Group event!

Get display value of variable from hr case variable editor

kali
Tera Contributor

Hi All,

I am using a system property to keep all the variable backend name and passing to a function to get the value , now the problem is while passing from the system property i am passing string as well as reference value, how to get the display value of reference,i am using gliderecord object hrcase. Please help me on this, thanks in advance

hrCase.variables[fieldname];

6 REPLIES 6

pratikjagtap
Giga Guru

Hi @kali ,

Here’s how you can handle both string and reference types dynamically:

var fieldName = gs.getProperty('your.property.name'); // This gives you the variable name
var variableValue = hrCase.variables[fieldName];

if (variableValue != null) {
var displayValue = variableValue.getDisplayValue ? variableValue.getDisplayValue() : variableValue;
gs.info("Display Value: " + displayValue);
} else {
gs.info("Variable not found or is null.");
}

Explanation:

  • variableValue.getDisplayValue checks if the method exists (i.e., it's a GlideElement like a reference field).
    If it's a reference, getDisplayValue() returns the human-readable name.
    If it's a simple string or non-reference, it just returns the value directly.

If my response helped, please hit the 👍Thumb Icon and accept the solution so that it benefits future readers.

 

Regards,
Pratik



Hi @pratikjagtap ,

I would like to check if the variable is choice or Yes/No, then it should return the label not the backend choice, can you please modify the above code and let me know

Ravi Gaurav
Giga Sage

Hi @kali 
can you check the below code with your requirement:

var fieldName = gs.getProperty('your.property.name'); // System property holds variable backend name
var variableValue = hrCase.variables[fieldName];

if (variableValue != null) {
var displayValue;


if (variableValue.getDisplayValue) {
displayValue = variableValue.getDisplayValue();
}
else {

displayValue = variableValue;
}

// Special handling for Yes/No and Choice variables

if (typeof variableValue == 'object' && variableValue.getQuestion) {
var question = variableValue.getQuestion();
var label = question.getLabel(variableValue);
if (label)
displayValue = label;
}

gs.info("Display Value: " + displayValue);
}
else {
gs.info("Variable not found or is null.");
}

Ankur Bawiskar
Tera Patron

@kali 

please share your complete script here

💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏