- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-12-2022 06:33 AM
hi
My requirment is i want to display a field and it should be mandatory, i want to display a field when defects is selected in a list collector variable, but iam getting the field also when i select the other variable in the list collector? i have written on change client script but it is displaying the new field for two values where as i want to display value only when defects is selected?
kindly look into screenshots.
the new field should not be visible while selecting incident but what happening is that if i select defects and remove defects and select incident the new field is not hiding
Solved! Go to Solution.
- Labels:
-
Change Management

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-12-2022 08:32 AM
Hey Sai,
Did the solution worked for you?
Cheers..!
Tushar
Cheers..!

Happy Learning:)

Tushar

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-12-2022 07:20 AM
Hello sai,
As it is list collector we have to use the for loop for checking the sys_id of the list collector. Let me take you through this.
Steps we are going to follow:
1.Create a system property and paste the sysid into it and use that in the script include.
2. Create a onchange client script with the code below.
3. Create a client callable script include paste the code below.
I have done things on the group list you can replace with yours.
1. create the system property & give the sys in the value section for which you want to make mandatory field.
2. Client Script - on change on the field "group List"
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
alert(newValue); //for checking whether we are getting the correct sys_id from the list collector
var ga = new GlideAjax('getListValue');
ga.addParam('sysparm_name', "checkchoice");
ga.addParam('sysparm_list', newValue); //List collector field sending to server side
ga.getXML(Populate);
function Populate(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
if (answer == 1 || answer == '1') {
alert("the answer is " + answer); //for checking the return value
g_form.setDisplay('company', true);
g_form.setMandatory('company', true);
}
} //Type appropriate comment here, and begin script below
}
3. Script Include
var getListValue = Class.create();
getListValue.prototype = Object.extendsObject(AbstractAjaxProcessor, {
checkchoice:function(){
var list_value = this.getParameter('sysparm_list');
var flag = 0;
var myArray = list_value.split(',');
for (var i = 0; i < myArray.length; i++) {
if (myArray[i] == gs.getProperty('list_choice_default')) {//Calling the property
//if (myArray[i] == '75d20d9f87ea8110b23b4087cebb3579') { //if you want to check with the sys id of the list collector variable
flag = 1;
break;
}
}
return flag;
},
type: 'getListValue'
});
OUTPUT
I have selected group 2 in list & company field got mandatory
Mark it helpful & correct, If applicable
Cheers..!
Happy Learning
Tushar
Cheers..!

Happy Learning:)

Tushar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-12-2022 07:52 AM
You can replace your for..in loop in your script include to use Array.prototype.some. It's shorter and I find it a little easier to read. You'd also need to update the client script to check for true/false instead of 1/0.
var getListValue = Class.create();
getListValue.prototype = Object.extendsObject(AbstractAjaxProcessor, {
checkchoice:function(){
var list_value = this.getParameter('sysparm_list');
var myArray = list_value.split(',');
return myArray.some(function(choice) { return choice == gs.getProperty('list_choice_default');});
},
type: 'getListValue'
});

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-12-2022 08:04 AM
Hey
Thanks for the suggestion.
Cheers..!
Tushar
Cheers..!

Happy Learning:)

Tushar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-12-2022 08:16 AM
sys id do i need to paste of the list collector or the the defects sys id which i need to paste on system property?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-12-2022 08:28 AM
you have to take the sys_id of defects-> which ever you are entering to the list collector.
Cheers..!
Tushar
Cheers..!

Happy Learning:)

Tushar