need to give the permission to users based on view

siva14
Tera Contributor

Hello all,

 

i have small requirement that , on custom table list view i have created a new view name called "XXX" , so i need to give list edit permission to the users to edit the fields on list view when they are on view called "XXX", 

i have used below script but the script is not working , any suggestion that would be great help.

Note - I have created new role to those users.

 

(function() {
    var currentView = gs.getSession().getClientData('sysparm_view');
    if (currentView === 'XXX') {
        answer = true;
    } else {
        answer = false;
    }
})();
 
#ACL #ACL SCRIPT #SECURITY ADMIN
1 ACCEPTED SOLUTION

folusho
Tera Guru

@siva14 

Please try this script below:

 

/* Restrict to view = “XXX” */
(function () {

    var view = 'default';

    // When a browser call is in play, get the ?sysparm_view=value
    var req = gs.action.getGlideRequest();   // null if no request
    if (req) {
        var v = req.getParameter('sysparm_view');
        if (v) {
            view = v;
        }
    }

    // Only allow if the requested view is “XXX”
    answer = (view === 'XXX');
})();

 

Why switch from gs.getSession().getClientData('sysparm_view')?

  1. gs.action.getGlideRequest() is the supported server‑side way to read URL parameters such as sysparm_view.

  2. getClientData() relies on UI‑only session data... it isn’t always populated when the script runs in background or via API.

View solution in original post

7 REPLIES 7

Ankur Bawiskar
Tera Patron
Tera Patron

@siva14 

So list edit should be allowed only for XXX view?

Using list_edit table ACL and checking the view name in that ACL script should help

try this

var url = gs.action.getGlideURI();
if(url.indexOf('XXX') > -1)
answer = true;
else
answer = false;

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

Hi @Ankur Bawiskar ,

 

i have used above code, but it's not working , any alternative solution that would be helpful

 

siva14_0-1746635771601.png

 

@siva14 

Can you try this?

 

/* Restrict to view = “XXX” */
(function () {

    var view = 'default';

    // When a browser call is in play, get the ?sysparm_view=value
    var req = gs.action.getGlideRequest();   // null if no request
    if (req) {
        var v = req.getParameter('sysparm_view');
        if (v) {
            view = v;
        }
    }

    // Only allow if the requested view is “XXX”
    answer = (view === 'XXX');
})();