how to make a workspace readonly for users

konijetisumanth
Giga Guru

Hi Community 

 

I need a help in how to make a SAM or HAM workspaces read only for certain role users in servicenow.

4 REPLIES 4

Anurag Tripathi
Mega Patron
Mega Patron

Hi,

Each view has a name, You need to find the name for SAM/HAM workspace view on the table and then run a client script for that view only 

 

To Run client script for a particular view You need to uncheck the Global field and in the View Field Add the name of the view 

 

This is the script that will make all fields read only, club this with your role check and run this

 

var fields = g_form.getEditableFields();
         for (var x = 0; x < fields.length; x++) {
           g_form.setReadOnly(fields[x], true);
}

 

-Anurag

Community Alums
Not applicable

dreinhardt
Tera Sage

Hi @konijetisumanth,

 

Thanks to @Community Alums & @Anurag Tripathi for these details, wasn't aware of this.

 

The solutions mentioned is a great starting point and help to restrict the relevant information in the tables used (e.g. read-only). However, it should also be noted that the entire SAMP module is designed for the standard roles (sam_user, sam_admin, sam_developer, sam_integrator). This is clearly shown by the fact that certain functions/actions check for these roles in the script during execution and these values are "hard coded". It will not be possible to prevent functions in certain parts of the SAMP workspace as soon as a user has the sam_user role (role is necessary to work with the module)

 

With Xanadu, ServiceNow introduced the following feature for EAM and I'm looking forward to see the same for SAM and HAM - Personalized workspaces for medical and facility industries (servicenow.com)

 

Best, Dennis

Should my response prove helpful, please consider marking it as the Accepted Solution/Helpful to assist closing this thread.

Sumanth16
Kilo Patron

Hi @konijetisumanth ,

 

function onLoad() {
    //Type appropriate comment here, and begin script below
    var url = top.location.href; // getting the URL Link
    var pathname = new URL(url).pathname; // getting the Path workspace : now/risk/, Native :now/nav/ui/.
    pathname = pathname.split('/');
    var ur = pathname[2];// getting if its a workspace or native
    if ( ur == 'nav') {
        var fields = g_form.getEditableFields();
        for (var x = 0; x < fields.length; x++) {
            g_form.setReadOnly(fields[x], true);
        }
    }else{
        fields = g_form.getEditableFields();
        for ( x = 0; x < fields.length; x++) {
           g_form.setReadOnly(fields[x], false);
        }
    }
}

If I could help you with your Query then, please hit the Thumb Icon and mark it as Correct !!

 

Thanks & Regards,

Sumanth Meda