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

ServiceNow Use6
Tera Guru

Hi @Omkar Kumbhar,

 

Right now all the variables at the task level are editable, is there any way we can restrict the editable variables to only some and all the list of variables.

 

Regards

Suman P.

ServiceNow Use6
Tera Guru
function onLoad() {
    if (g_user.hasRole('sam_admin') || g_user.hasRole('admin')) {
        g_form.setMandatory('variables.installation_upgrade_needed', true);
        g_form.setMandatory('variables.allocation_link', true);
    } else {
        g_form.setVisible('variables.installation_upgrade_needed', false);
        g_form.setVisible('variables.allocation_link', false);
        // Or use: g_form.setReadOnly(...) if you want them visible but not editable
    }
}

 

I try to use just onLoad instead of scratchpad