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:02 AM
Hi @Lisa Goldman ,
That's what I have been mentioning since the beginning 😀
If you still want to check against the name you can check my last response and update the variables lookup value field
Please mark my answer as helpful/correct if it resolves your query.
Regards,
Chaitanya
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-17-2025 09:50 AM
try
var applicationName = newValue;
or
var applicationName = g_form.getDisplayBox('business_application').value;
one of above should work.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-17-2025 10:22 AM
Thank you @Harmeet2Singh
We have tried both suggestion and it is not working.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-18-2025 03:30 AM
Hi Lisa,
can you try removing checkbox of isolate script and then use
var applicationName = g_form.getDisplayBox('business_application').value;
Also check alert on application name just after this line, to check if application name is being captured or not.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-17-2025 10:56 AM - edited 07-17-2025 11:11 AM
It appears you are trying to alert the user whenever the "business_application" variable of the Business Application VS variable set is changed such that the display value is "Maximo". Assuming this is correct then I think there is a flaw in your approach and thus in the way you built your if condition.
First of all the approach is going to depend on the variable type used for "business_application". Based on your use of the getDisplayValue() method I assume it is a reference field. If this is the case then its going to specifically pass a sys_id. In this instance you could use something like follows in your client catalog script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
//Type appropriate comment here, and begin script below
var applicationSysID = 'sys_id'; //Hardcode the sys_id of your matching record
if (newValue === applicationSysID) {
alert('Maximo'); //Hardcode the alert text.
}
}
If you want to use the display value of the selected record from your Lookup Select box then I believe you have to use g_form.getReference('business_application').displayfield. In this situation your client catalog script might look something like this:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
//Type appropriate comment here, and begin script below
var applicationName = g_form.getReference('business_application').diplayfield; //display field is the field returned when you use getDisplayValue on a record for the referenced table
if (applicationName == 'Maximo') {
alert(applicationName);
}
}
If you wanted to support a list of different sys_ids that would generate the alert then you could do it a slightly different way. First you would need a system property or global variable that contains the sys_id(s) that when selected would create the alert. Then you would use a script include, passing the newValue from the onChange script. The script include would check if the newValue matches and return true and the display value of the matching record required for the alert. Then your if statement would simply look at the script include response and if true would then alert the display value returned.
While definitely not best practice you could also perform multiple if statements, one after the next to check every possible sys_id you would want an alert for.
EDIT: I just wanted to include information on the getDisplayBox() method. This does not reliably work in this situation because it references the DOM. Since you are inside a variable set the DOM elements are rendered differently than they are on a standard form. Thus the reason it likely isn't working in this situation.