scratchpad field set readonly for non ServiceDesk group

ServiceNow Use6
Tera Guru

Hi,

 

I am trying to set a variable in the catalog item to read only for other than Service Desk group at the sc_req_item level. I tried it but still non Service Desk group is able to edit it. Kindly help.

 

1.jpg

 

2.jpg

 

(function executeRule(current, previous /*null when async*/ ) {

    if(gs.getUser().isMemberOf('Service Desk'))
	{
        g_scratchpad.variable = true;
    }

})(current, previous);

 

3.jpg

 

function onLoad() {
   
   if(g_scratchpad.variable!=true){
	g_form.setReadOnly('features', true);
   }
   
}

 

4.jpg

 

Regards

Suman P.

6 REPLIES 6

M Iftikhar
Mega Sage

Hi @ServiceNow Use6

 

The logic you write seems ok, double check your business rule condition "item is a" mentioned in your shot:

MIftikhar_0-1758021976176.png

 

Does it make any sense?

 

hope this helps!

 

Thanks & Regards,
Muhammad Iftikhar
If my response helped, please mark it as the accepted solution and helpful so others can benefit as well.

M Iftikhar
Mega Sage

@ServiceNow Use6 ,

I think issue is in condition that you are using in BR (item is a) may be because of it is not triggering.
I just tested on my PDI below scripts are working.

(function executeRule(current, previous /*null when async*/ ) {

    if(gs.getUser().isMemberOf('Service Desk'))
    {
        g_scratchpad.result = true;
    }
    else{
        g_scratchpad.result = false;

    }
    gs.addInfoMessage("Result is " + g_scratchpad.result );

})(current, previous);
 
function onLoad() {
     if(!g_scratchpad.result){
    g_form.setReadOnly('feature', true);
   }
}
 
Thanks & Regards,
Muhammad Iftikhar
If my response helped, please mark it as the accepted solution and helpful so others can benefit as well.

Hi @M Iftikhar,

 

I will test, i will let you know.

 

Regards

Suman P.

@ServiceNow Use6 

please check my above response regarding workaround.

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader