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

It has been created from ui builder not as declarative action 

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