Show field message on LIST collector variable based on condition
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-22-2024 11:39 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-22-2024 12:05 PM - edited 07-22-2024 12:31 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-22-2024 12:22 PM
I tried this but it is not working
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-22-2024 12:27 PM - edited 07-22-2024 12:32 PM
Can you elaborate your scenario. also check the update code
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-22-2024 12:31 PM
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');
}
}
}