Hide add request change button base don condition on project workspace

mohammadzey
Tera Contributor

mohammadzey_0-1779260532193.png

Hi everyone,

 

I’m trying to conditionally hide the "Add Request Change" button based on the project type.

The goal is to make the button visible only for specific project types, and hidden for others depending on predefined conditions.


Thanks,

1 ACCEPTED SOLUTION

HarishKumar6668
Tera Guru

Hi @mohammadzey,

The buttons such as Add Issue, Add Decision, etc., are being rendered from the Scripted REST Resource(getConfig) available in the sys_ws_operation table.

HarishKumar6668_0-1779277621047.png

 

Within the Scripted REST Resource, the RIDACWorkspace Script Include is being invoked. From this Script Include, the getRIDACConfig() method is responsible for returning the toolbar button configuration.

 
getRIDACConfig: function(topTaskId, parentTable) {
		var ridacColumns = new RIDACColumns().get();
		var canCreateRIDACList = [];
		var ridacEntitesHasRecordsCount = 0;
		const toolBarConfig = this._getToolbarConfig(topTaskId, parentTable);
		var parentGr = new GlideRecord(parentTable);
		parentGr.get(topTaskId);
		if(toolBarConfig && !toolBarConfig.canRead){
			return {
				status: 'error',
				statusCode: '403'
			};
		}
		for(var i=0; i < this.ridacTables.length; i++) {
			var table = this.ridacTables[i];
            var gr = new GlideRecord(table);
			if (table === 'risk') {
                gr.addQuery('task', topTaskId);
            } else {
                gr.addQuery('parent', topTaskId);
            }
			gr.setLimit(1);
            gr.query();
			
			if(gr.getRowCount())
				ridacEntitesHasRecordsCount++;
			
			if(gr.canCreate()){
				var ridac = {};
                ridac.id = table;
                ridac.label = gs.getMessage('Add {0}', this.typeMap[table]);
                canCreateRIDACList.push(ridac);
			}
		}
		
		return {
            status: 'success',
            statusCode: '200',
            columns: ridacColumns,
			config: this.getConfig(ridacEntitesHasRecordsCount),
			toolbar: toolBarConfig,
			groupBy: ['ridacType'],
			moreActions: gs.getMessage('More actions'),
			canCreateRIDACList: canCreateRIDACList,
			parentDomain: parentGr.getValue('sys_domain'),
			translationMap: this.typeMap
        };
	}

You can enhance the logic as per your requirement inside the method.

 If this helps, please mark it as Helpful or accept it as a Solution.

 

Regards,
Harish

View solution in original post

6 REPLIES 6

Ankur Bawiskar
Tera Patron

@mohammadzey 

it comes from this component, deep dive in UI builder and see

Those are not Declarative Actions

https://instanceName.service-now.com/now/builder/ui/edit/experience/8f7db3b507223010188ca2324dd300be/576c9b4a07623010188ca2324dd3008c/176c534a07623010188ca2324dd300b0

55.png

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

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

From here it will hide the full button "Add Risk" and what are under it, i only need to hide add request change and based on a condition 

@mohammadzey 

you will have to see how the other 3 buttons are added by exploring that UI builder component and then handle the logic

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

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

Tanushree Maiti
Tera Patron

Hi @mohammadzey 

 

 Refer: https://www.servicenow.com/community/developer-forum/configuring-new-project-workspace-remove-button...

 

https://www.servicenow.com/community/itsm-forum/how-to-hide-new-button-on-related-list-in-workspace/...

 

Please Accept the solution if it assisted you with your question & Mark this response as Helpful.
Regards
Tanushree Maiti
ServiceNow Technical Architect
LinkedIn: https://www.linkedin.com/in/tanushreemaiti