Excluding Item based on List Collector Item

Walter Toney
Tera Expert

I have been given a requirement to exclude "Modify" from the select box item in a Variable Set. when "RFD" is selected on the Request the RFD value is coming from list collector in the "Custom Action Table" we have built. I'm trying to build a Client script to do this. I have a similar script that excludes but that is just for a Yes/No variable. but it's looking at a variable not a external table. Based on research and trying started down this path but i can't get it to work.. can someone help me to understand what i'm not seeing

 

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

var list = g_form.getValue('application_project'); //getting value of list collector
if(list.indexOf('RFD') > -1 ){  //item in list collector
g_form.removeOption('logging_account', 'Modify'); //action to proform when list selected

}
}

5 REPLIES 5

Tushar
Kilo Sage
Kilo Sage

The script you provided seems to be on the right track. However, there are a few points to consider:

  1. Make sure the variable set containing the select box variable is loaded before the script executes. If the variable set is loaded asynchronously, you might need to wrap the script in the g_form.$document.ready() function to ensure it runs after the form elements are available.

  2. Confirm that the value of the list collector variable is correctly retrieved. You can add a console.log(list) statement to check if the value is as expected. Open the browser's developer console to view the logged output.

  3. Verify that the option label you want to exclude from the select box is indeed "Modify". Double-check the spelling and case sensitivity.

Here's an updated version of your script, taking these considerations into account:

 

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

g_form.$document.ready(function () {
var list = g_form.getValue('application_project');
if (list.indexOf('RFD') > -1) {
g_form.removeOption('logging_account', 'Modify');
}
});
}

 

By using the g_form.$document.ready() function, the script will wait for the form to be fully loaded before executing, ensuring that the form elements are accessible.

Sagar Pagar
Tera Patron

Hi @Walter Toney,

 

Try this updated scripts:

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

	var list = g_form.getValue('application_project'); //getting value of list collector
	if (list.toString().indexOf('RFD') > -1) { //item in list collector
		g_form.removeOption('logging_account', 'Modify'); //action to proform when list selected

	}
}

 

Also, make sure that Modify is correct value for that select box options.

 

Thanks,

Sagar Pagar

The world works with ServiceNow

Sorry I have not been able to look at this until now. I will work with it and let you know the results.

This did not Work. I believe it is because of my description... it's a MRVS not just a variable set

 

so... the user will select item from the List collector and based on that selection I want to have Modify off of the select box on a MRVS