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:44 PM
No its not working. to fix this I just made variable hidden on variable level post that I added below script now it's working perfectly.
any issue with this approach?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-16-2024 12:18 AM
@Nagesh5 ,
Please try this piece of code this is working for me
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");
g_form.setDisplay('additional_assignee_list',true);
}
else{
alert('Else');
g_form.setMandatory("Requester", false);
g_form.setDisplay('additional_assignee_list',false);
}
}
}
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-16-2024 12:39 AM
it's not working..let me explain if keyword is "Abraham" then requester field is visible and it should be mandatory at the time of on change it's working perfectly.
1.if item form loads it's should be hidden
2.If list collect does not have the value then also it should be hidden
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-16-2024 01:10 AM
@Nagesh5 ,
1.if item form loads it's should be hidden
Hide the variable by checking the hidden checkbox so at the time of form load it is hidden
2.If list collect does not have the value then also it should be hidden
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");
alert("newValue.length + " + newValue.length);
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);
alert("Length " + answer.length);
if (answer.includes("Abraham")) {
// g_form.setMandatory("Requester", true);
alert("IN IF Condition");
g_form.setDisplay('additional_assignee_list',true);
}
if(answer == null || answer.length == 0){
alert("Inside nukll");
g_form.setDisplay('additional_assignee_list',false);
g_form.setMandatory("Requester", false);
}
else{
alert('Else');
g_form.setMandatory("Requester", false);
g_form.setDisplay('additional_assignee_list',false);
}
}
}
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-16-2024 01:51 AM
the problem is If I hidden from variable level post submission of the request it is hiding in RITM level if that list collector having the value