Fields to be mandatory and visible at Task Level to a certain group
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-31-2025 12:36 AM
Hi,
My requirement is that some of the catalog variables are to be visible and mandatory to a certain group at Task level. I tried it but it is not working. All the fields are editable and these two required fields are not getting Mandatory. Kindly help.
function onLoad() {
if(g_scratchpad.huwi=='palisetty'){
alert('is equal to');
g_form.setMandatory('installation_upgrade_needed', true);
g_form.setMandatory('allocation_link', true);
}
(function executeRule(current, previous /*null when async*/) {
if(gs.getUser().isMemberOf('SAM ADMIN')){
g_scratchpad.huwi='palisetty';
}
})(current, previous);
All the fields are editable and these two required fields are not getting Mandatory.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-31-2025 12:57 AM - edited 07-31-2025 12:58 AM
Hello @ServiceNow Use6 ,
First try adding logs to check if you are getting value of g_scratchpad in client script from BR.
Later if it does not work try not using the Display business rule. Check by using the script include and glide Ajax in client script.
var CheckmemberOf = Class.create();
CheckmemberOf.prototype = Object.extendsObject(AbstractAjaxProcessor, {
checkGroupMember: function() {
var grp = this.getParameter('sysparm_grp');
return gs.getUser().isMemberOf(grp);
},
type: 'CheckmemberOf'
});
2. Use above script include from client side script.
function onLoad() {
var ga = new GlideAjax('CheckmemberOf');
ga.addParam('sysparm_name', 'checkGroupMember');
ga.addParam('sysparm_grp', 'use the sys_id of group here');
ga.getXML(checkGroup);
}
function checkGroup(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
if (answer == 'true') {
alert('Logged in User is part of group');
} else {
alert('Logged in User is not part of group');
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-31-2025 01:26 AM - edited 07-31-2025 01:26 AM
Hi @Omkar Kumbhar,
I tried like this, it gives me 'undefined'. If it is wrong please correct me.
function onLoad() {
alert(g_scratchpad.huwi);
// if(g_scratchpad.huwi=='palisetty'){
// alert('is equal to');
// g_form.setMandatory('installation_upgrade_needed', true);
// g_form.setMandatory('allocation_link', true);
// }
Regards
Suman P.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-31-2025 01:30 AM
@ServiceNow Use6 try
alert('print the value'+g_scratchpad.huwi);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-31-2025 01:51 AM
Hi @Omkar Kumbhar,
I am getting same undefined. Maybe I will try GlideAjax and let you know how far i could.
Regards
Suman P.