Client Script in MRVS

dev_K
Tera Contributor

Hi all,

 

 

I have a catalog item request with few variables like 'security zone' and 'data center'. Then I have also a MRVS that has a variable 'the_mountpoint', and I want this variable to be populated with values from those 2 fields, however it seems g_form.getValue() is not working... Any solutions?

 

 

dev_K_0-1726496819755.png

 

3 REPLIES 3

Brad Bowman
Kilo Patron
Kilo Patron

In your Catalog Client Script that applies to the MRVS you can use

g_service_catalog.parent.getValue('variable_name');

in place of g_form.getValue

Hi Brad,

 

 

This indeed helped. I can populated the field with the values however one is getting me the sysID as the value comes from a reference table.

 

dev_K_0-1726558487198.png

 

 

What can I do to get the display value? I tried getDisplayValue() method but seems not to work:

 

function onLoad() {
    // Add logging to check if the onLoad function is triggered
    console.log("onLoad triggered");

    // Initially populate the_mountpoint_of_the_filesystem on load
    updateMountPoint();

    // Add listeners for variable changes, if needed
    g_form.listenForValueChange('environment', updateMountPoint);
    g_form.listenForValueChange('business_app_name', updateMountPoint);
}
function updateMountPoint() {
    // Add logging to check if updateMountPoint is called
    console.log("updateMountPoint called");
    // Use g_service_catalog.parent to retrieve the variables from the parent form
    var environment = g_service_catalog.parent.getValue('environment');
    var businessAppName = g_service_catalog.parent.getValue('business_app_name');

    // Log the values for debugging
    console.log("Environment: ", environment);
    console.log("Business App Name: ", businessAppName);
    // Check if both fields have values
    if (environment && businessAppName) {
        var mountPoint = environment + " / " + businessAppName;
        g_form.setValue('the_mountpoint_of_the_filesystem', mountPoint);
        console.log("Mount Point set to: ", mountPoint);
    } else {
        // If either field is empty, set the mountpoint to an empty string
        g_form.setValue('the_mountpoint_of_the_filesystem', '');
        console.log("Mount Point set to empty");
    }
}

The easiest thing to add to the script is a GlideRecord on the reference table.  Use the value retrieved from the parent as the sys_id / record to retrieve, then use the Name field or whatever from that record to populate the MRVS variable.