Issue with Accessing Variable Value in Variable Set
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-17-2025 08:48 AM
Hello,
I need help retrieving the value from a Variable Set.
Here's what I’ve tried so far, but it’s not triggering the alert. Thank you
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
//Type appropriate comment here, and begin script below
var applicationName = g_form.getDisplayValue('business_application');
if (applicationName === 'Maximo') {
alert(applicationName);
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-17-2025 11:10 AM
Thank you so much for the detailed explanation. As I mentioned earlier in the thread, hardcoding the sys_id is working, and the code I’m using is similar to what you suggested.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return; // Prevents script from running during form load or if no value is selected
}
alert(newValue);
if (newValue === 'bc29e258db2f9c1005fddbd4ce96195b') { //Maximo
g_form.setDisplay('service_type', false);
} else {
g_form.setDisplay('service_type', true);
}
}
However, I’m still wondering if there’s a way to retrieve the actual display name instead of the sys_id.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-17-2025 11:20 AM - edited 07-17-2025 01:54 PM
I haven't done it but you might be able to use the getDisplayValue() method in combination with the getReference...try something like this for the if statement:
g_form.getReference('business_application', function(ref) {
if (ref && ref.getDisplayValue() === 'Maximo') { //This is checking that getReference returned a valid record and also your display value at the same time.
alert('Maximo');
}
});
This could represent a much easier way to cover multiple possible business_application selection if they all share a single display value.
Edit: If this works then it would present a much easier way to perform this type of check that wouldn't break if the display value field were changed or the referenced record sys_id was different between instances or changed.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-17-2025 11:46 AM
After trying your suggested code, the alert is not triggering at all. Thank you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-17-2025 12:00 PM
When you posted this reply I looked at the code and there was an error if you copied exactly. It started with g-form instead of g_form...
I corrected it in the above post, if you copied it exactly try it after fixing that little typo.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-17-2025 01:01 PM
I noticed there was a syntax error in the code, so I corrected it and tested again — but the alert still didn’t fire. Again, thank you so much for your time and effort. Will hardcode the sys_id to make it works.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue === '') {
return;
}
g_form.getReference('busines_application', function(ref) {
if (ref && ref.getDisplayValue() === 'Maximo') { //This is checking that getReference returned a valid record and also your display value at the same time.
alert('Maximo');
}
});
}