Show field message on LIST collector variable based on condition

snow34
Tera Contributor

I have variable named called as "Environment" type of this variable is list collector , in this collector i have three values DEV, IST, PROD so whenever PROD is selected i want to show , show field message .

 

Please help me with this as this is very urgent

7 REPLIES 7

Satishkumar B
Giga Sage
Giga Sage

Hi @snow34 

 

To display a message when the "PROD" environment is selected in a list collector variable on a ServiceNow form, you can use a client script

 

 

function onChange(control, oldValue, newValue, isLoading) {
    // Exit if the form is still loading
    if (isLoading || newValue === '') {
        return;
    }

    // Split the newValue into an array if it's a list collector
    var selectedValues = newValue.split(',');

    // Check if 'PROD' is in the selected values
    if (selectedValues.indexOf('PROD') > -1) {
        // Show an info message box
        g_form.addInfoMessage("You have selected the PROD environment.");
    }
}

 

 

……………………………………………………………………………………………………

Please Mark it helpful 👍and Accept Solution!✔️! If this helps you to understand. 

I tried this but it is not working 

Can you elaborate your scenario. also check the update code

I have explained in the description. I tried multiple scripts it's not taking value of List Collector .

 

below is the script which i have tried and i tried your script also but no luck

 

 

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}

var selectedValues = g_form.getDisplayValue('environment').split(',');

for (var i = 0; i < selectedValues.length; i++){

if (selectedValues[i]=='PROD') {

g_form.showFieldMsg('environment','your access canno be processed as it is not compliant with the Logical Access Security Standard 1-6.2(Developer Acess Environment). Please contact DNA Producton Services(dnaprod@rbc.com) for further details','error');
}


}

}