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.

Export Context Menu in List View

ican
Tera Contributor

Use Case:

I want to hide export context menu from my custom tables if the logged in user is not member of a specific group.

 

I have added this line in the Export Context menu Condition:

!ListProperties.isRelatedList() && !ListProperties.isRefList() && new TestSI().disableExport(ListProperties.getTable())

 

Script Include:

	disableExport: function(tableName) {
                var groupID = gs.getProperty('Allowed_GroupID');
		var tablesHidden = ['custom_table1', 'custom_table2', 'custom_table3', 'custom_table4', 'custom_table5'];
		if(tablesHidden.indexOf(tableName) != -1) {
			return gs.getUser().isMemberOf(groupID);
		} else {
			return true;
		}
	},

 

Currently its not working.

I have tried putting logs but after a time the logs are not showing even if i refresh the list view.

 

Need help.

Thanks.

 

6 REPLIES 6

Ankur Bawiskar
Tera Patron
Tera Patron

@ican 

I hope you already overrode the OOTB export button for your custom table

update it as this

Note: I assume the system property contains comma separated sysIds of group

	disableExport: function(tableName) {
	    var groupID = gs.getProperty('Allowed_GroupID'); // I assume this contains comma separated sysIds of group
	    var tablesHidden = ['custom_table1', 'custom_table2', 'custom_table3', 'custom_table4', 'custom_table5'];
	    if (tablesHidden.indexOf(tableName) != -1) {
	        var gr = new GlideRecord("sys_user_grmember");
	        gr.addQuery("group.sys_id", "IN", groupID);
	        gr.addQuery("user", gs.getUserID());
	        gr.setLimit(1);
	        gr.query();
	        return gr.hasNext();
	    } else {
	        return true;
	    }
	},

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

groupID containts only 1 sysID

@ican 

then script shared by me should work fine for 1 sysId or more than 1

if you will always keep 1 sysId then no script include required

Simply use this

!ListProperties.isRelatedList() && !ListProperties.isRefList() && gs.getUser().isMemberOf(gs.getProperty('Allowed_GroupID'))

if in future that property might get updated with more than 1 then use script include

disableExport: function(tableName) {
	    var groupID = gs.getProperty('Allowed_GroupID'); // I assume this contains comma separated sysIds of group
	    var tablesHidden = ['custom_table1', 'custom_table2', 'custom_table3', 'custom_table4', 'custom_table5'];
	    if (tablesHidden.indexOf(tableName) != -1) {
	        var gr = new GlideRecord("sys_user_grmember");
	        gr.addQuery("group.sys_id", "IN", groupID);
	        gr.addQuery("user", gs.getUserID());
	        gr.setLimit(1);
	        gr.query();
	        return gr.hasNext();
	    } else {
	        return true;
	    }
	},

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

when i override the OOTB export button in my custom tables, does this mean I will have 2 export buttons for my custom table?

Thanks.