Interested in a ServiceNow event built for developers? Registration for now[dev]26 is officially open!

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.

1 ACCEPTED SOLUTION

Hi @Ankur Bawiskar,

I am definitely not as good as you, but I can guarantee we can use g_scratchpad for catalog item. The only change i made is checking the checkbox in the catalog client script.

 

5.jpg

 

Regards

Suman P.

View solution in original post

9 REPLIES 9

miftikhar20
Kilo Patron

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.

Thanks & Regards,
Muhammad Iftikhar

If my response helped, please mark it as the accepted solution so others can benefit as well.

miftikhar20
Kilo Patron

@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.
Thanks & Regards,
Muhammad Iftikhar

If my response helped, please mark it as the accepted solution so others can benefit as well.

Hi @miftikhar20,

 

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  ||  ✨ 10x ServiceNow MVP  ||  ✨ ServiceNow Community Leader