Mandate the field based on the particular keyword in the List type fiedl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-15-2024 07:33 PM
Hello Community,
we have list collector variable on the catalog item and where user can select multiple values and We are looking for the way if particular keyword identified then another variable need to make mandatory. We have below code and it's not working can anyone help where we are missing the logic?
Client Script :--------------------
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-15-2024 11:05 PM - edited 08-15-2024 11:10 PM
@Nagesh5 ,
Please edit this client Script
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
//Type appropriate comment here, and begin script below
// var user = g_form.getValue("additional_assignee_list");
var ga = new GlideAjax("checkUser");
ga.addParam("sysparm_name", "getUsers");
ga.addParam("sysparm_value", newValue);
alert("HERE IN CS = " + newValue);
ga.getXML(userCheck);
function userCheck(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
//var ouput = JSON.parse(answer);
if (answer.includes("Abraham")) {
g_form.setMandatory("Requester", true);
alert("IN IF Condition");
}
else{
alert('Else');
g_form.setMandatory("Requester", false);
}
}
}
Now if it enter in else condition that field is no more mandatory.
Please mark my answer correct and helpful if this works for you
Thanks and Regards
Sarthak
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-15-2024 11:15 PM
It's working perfectly and how to hide this field if list collector not having this keyword ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-15-2024 11:20 PM
@Nagesh5 ,
In Else part of client script add this line
g_form.setDisplay('user_check',false); // backend value of field user_check
Please mark my answer correct and helpful if this works for you
Thanks and Regards
Sarthak
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-15-2024 11:29 PM - edited 08-15-2024 11:35 PM
Apologies for the confusion it's should be hidden until that value available in list collector at the time form load as well because if list collector is empty then also it's appearing
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-15-2024 11:35 PM
@Nagesh5 ,
You can add that line on the top of client script
g_form.setDisplay('user_check',false);
or
you can also make that field hidden you can add in if condition
g_form.setDisplay('user_check',true);
You can do in any of way
Please mark my answer correct and helpful if this works for you
Thanks and Regards
Sarthak