Get display value of variable from hr case variable editor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-20-2025 09:09 AM
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];
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-20-2025 11:03 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-20-2025 10:05 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-20-2025 11:26 PM - edited 10-20-2025 11:27 PM
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.");
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-21-2025 02:22 AM
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! 🙏