Fields to be mandatory and visible at Task Level to a certain group

ServiceNow Use6
Tera Guru

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.

 

 

Requirement.png

 

1.png

2.png

 

function onLoad() {
   
   if(g_scratchpad.huwi=='palisetty'){
	alert('is equal to');
	g_form.setMandatory('installation_upgrade_needed', true);
	g_form.setMandatory('allocation_link', true);
   }

 

3.png

 

4.png

 

(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.

 

5.png

 

 

6 REPLIES 6

Omkar Kumbhar
Mega Sage
Mega Sage

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');
    }
}

 

If I was able to help you with your case, please click the Thumb Icon and mark as Correct.

ServiceNow Use6
Tera Guru

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.

@ServiceNow Use6 try 

   alert('print the value'+g_scratchpad.huwi);
If I was able to help you with your case, please click the Thumb Icon and mark as Correct.

Hi @Omkar Kumbhar,

 

I am getting same undefined. Maybe I will try GlideAjax and let you know how far i could.

 

Regards

Suman P.