question on incident form impact choices
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-03-2024 04:34 AM
i have one requirement, if user's department is 'IES' then he should not see impact choices and if user's department is not 'IES' then he should see impact choices. So for this I have written one onchange client script, but this client script not work properly, Select any user, it is going in the else condition only if condition not working in this script So can anyone help me on this where is the mistake on my code.
Please find the below code :
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-03-2024 04:39 AM
Hi @Mani60 ,
Corrected Script:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
// Get the department of the current user
var user = g_user.userID;
var userGR = new GlideRecord('sys_user');
if (userGR.get(user)) {
var department = userGR.getValue('department');
var deptGR = new GlideRecord('cmn_department');
if (deptGR.get(department)) {
var deptName = deptGR.getValue('name');
if (deptName === 'IES') {
alert(userGR.getValue('name'));
alert(deptName);
g_form.removeOption('impact', '7');
g_form.removeOption('impact', '5');
g_form.removeOption('impact', '6');
} else {
alert("Department is not 'IES'");
g_form.addOption('impact', '5', 'Entire');
g_form.addOption('impact', '6', 'Team');
g_form.addOption('impact', '7', 'Single');
}
}
}
}
If you find my response helpful, please consider marking it as the 'Accepted Solution' and giving it a 'Helpful' rating. Your feedback not only supports the community but also encourages me to continue providing valuable assistance.
Thanks,
Amitoj Wadhera
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-03-2024 04:51 AM
Hi @Mani60
refer to the below link.
Thanks
dgarad
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-03-2024 05:03 AM - edited 06-03-2024 05:09 AM
Hi @Mani60 ,
You can achieve this using getReference function. I have added the demo code, you can modify it according to your requirement. I have left placeholders for you to fill in the details like "sys_is of IES department" and in if and else condition.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
g_form.getReference('caller_id',myfunc);
function myfunc(val){
if(val.department == 'sys_id of IES Department'){
g_form.addInfoMessage('in if');
//Add you if logic here
}
else{
g_form.addInfoMessage('in else');
//Add you else logic here
}
}
}
Hope this helps you.