Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

get view name from list control omit new condition script

ggg
Giga Guru

I need to omit the NEW button from a List based on the view.

In one view I want the NEW button to display, in the other I do not.

in a Client Script you can use getView(); that does not work in this condition script.

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

you can use the approach of ACL;

open create ACL and in script section have this

answer = determineVisible();

function determineVisible(){  

var viewName = '';

var map = gs.action.getGlideURI().getMap();

if (map.get('sysparm_view') != null) {

 viewName= map.get('sysparm_view').toString();

if(viewName == 'self_service')

return true; // show new button

else if(viewName == 'xyz')

return false; // hide new button 

}

}

Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
Ankur

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

View solution in original post

10 REPLIES 10

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

you can use the approach of ACL;

open create ACL and in script section have this

answer = determineVisible();

function determineVisible(){  

var viewName = '';

var map = gs.action.getGlideURI().getMap();

if (map.get('sysparm_view') != null) {

 viewName= map.get('sysparm_view').toString();

if(viewName == 'self_service')

return true; // show new button

else if(viewName == 'xyz')

return false; // hide new button 

}

}

Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
Ankur

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

Community Alums
Not applicable

Hi Ankur,

 

I have a similar requirement for list view like list view should be read-only for specific view.

i tried your code but its not working as per view.

 

 

Regards,

Imam 

Try adding log statements and check once.

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

Community Alums
Not applicable

HI Ankur,

 

In below code i have added logs but its not getting in system Logs 

its getting non-editable to complete table not for the specific view

answer = determineVisible();

function determineVisible(){

var viewName = '';

var map = gs.action.getGlideURI().getMap();
gs.log("map::"+map);
if (map.get('sysparm_view') != null) {
gs.info("inside if::");
viewName= map.get('sysparm_view').toString();
gs.info("viewName::"+viewName);

if(viewName == 'retail_store')
gs.info("viewName1::"+viewName);
return false; // show new button

 

}

}

 

Regards,

Imam