Unable to hide “Calculate Risk” button in Change Request – Service Operations Workspace

SangareswarK
Tera Contributor

Hello Community,

I am working on Change Request in Service Operations Workspace (SOW) and I want to hide the “Calculate Risk”  button that appears under the Risk Evaluation section.

What I have already checked:

System Definition -> UI Action

            Calculate Risk UI Action Workspace options are already unchecked

Now Experience Framework → UX Form Actions

           There is no UX Form Action related to Calculate Risk

 

 

How can Hide the Button  ("Calculate Risk") in SOW?

 

 

2 ACCEPTED SOLUTIONS

frviuf
Tera Sage

Hi @SangareswarK ,

The button visibility is controlled in this UX Client script:
https://<instance_name>.service-now.com/sys_ux_client_script.do?sys_id=d13fde4853aa1110532cddeeff7b12c0  

Add this to hide the Calculate risk button:

        // Hides Calculate Risk button
	if (riskActions.showCalculateRisk)
		riskActions.showCalculateRisk.hide = true;


The script should look like this:

/**
 * @param {params} params
 * @param {api} params.api
 * @param {any} params.event
 * @param {any} params.imports
 * @param {ApiHelpers} params.helpers
 */
function handler({ api, event, helpers, imports }) {

	const riskActions = {
		...api.state.riskActions
	};
	api.state.calculateRisk.dryRun = true;

	if (!(api.data.risk_evaluation_change.output || api.data.calculate_change_risk.output))
		return;

	let showRiskActions = null;

	if (api.data.risk_evaluation_change.output)
		showRiskActions = api.data.risk_evaluation_change.output;

	if (api.data.calculate_change_risk.output && api.data.calculate_change_risk.output.result)
		showRiskActions = api.data.calculate_change_risk.output.result;

	let count = 0;
	if (showRiskActions) {
		Object.keys(showRiskActions).map(id => {
			riskActions[id] = showRiskActions[id];
			if (id !== 'changeRiskDetails' && !riskActions[id].hide)
				count++;
		});
	}

	if (count > 1) {
		let primaryId = null;
		if (!riskActions.showCompletedRiskAssessment.hide)
			primaryId = 'showCompletedRiskAssessment';
		else if (!riskActions.showRiskAssessment.hide)
			primaryId = 'showRiskAssessment';
		else if (!riskActions.showCalculateRisk.hide)
			primaryId = 'showCalculateRisk';
		else if (!riskActions.showChangeRiskDetails.hide)
			primaryId = 'showChangeRiskDetails';

		Object.keys(riskActions).map(id => {
			if (id !== 'changeRiskDetails' && id !== primaryId)
				if (!riskActions[id].hide)
					riskActions[id].hide = true;
		});
	}

        // Hides Calculate Risk button
	if (riskActions.showCalculateRisk)
		riskActions.showCalculateRisk.hide = true;


	api.setState('riskActions', riskActions);
}

 

View solution in original post

Matthew_13
Kilo Sage

@SangareswarK - 

This is a common SOW gotcha.

The “Calculate Risk” button isn’t coming from a UI action or UX Form action. In ServiceNow, it’s rendered by the Risk Evaluation workspace component, which is why unchecking those options doesn’t do anything.

To hide it basically you need to go into UI Builder, open the Change Request experience, select the Risk Evaluation component, and control its visibility there for example by role or condition. Thumbs up and mark answered if this helps my friend.

View solution in original post

4 REPLIES 4

frviuf
Tera Sage

Hi @SangareswarK ,

The button visibility is controlled in this UX Client script:
https://<instance_name>.service-now.com/sys_ux_client_script.do?sys_id=d13fde4853aa1110532cddeeff7b12c0  

Add this to hide the Calculate risk button:

        // Hides Calculate Risk button
	if (riskActions.showCalculateRisk)
		riskActions.showCalculateRisk.hide = true;


The script should look like this:

/**
 * @param {params} params
 * @param {api} params.api
 * @param {any} params.event
 * @param {any} params.imports
 * @param {ApiHelpers} params.helpers
 */
function handler({ api, event, helpers, imports }) {

	const riskActions = {
		...api.state.riskActions
	};
	api.state.calculateRisk.dryRun = true;

	if (!(api.data.risk_evaluation_change.output || api.data.calculate_change_risk.output))
		return;

	let showRiskActions = null;

	if (api.data.risk_evaluation_change.output)
		showRiskActions = api.data.risk_evaluation_change.output;

	if (api.data.calculate_change_risk.output && api.data.calculate_change_risk.output.result)
		showRiskActions = api.data.calculate_change_risk.output.result;

	let count = 0;
	if (showRiskActions) {
		Object.keys(showRiskActions).map(id => {
			riskActions[id] = showRiskActions[id];
			if (id !== 'changeRiskDetails' && !riskActions[id].hide)
				count++;
		});
	}

	if (count > 1) {
		let primaryId = null;
		if (!riskActions.showCompletedRiskAssessment.hide)
			primaryId = 'showCompletedRiskAssessment';
		else if (!riskActions.showRiskAssessment.hide)
			primaryId = 'showRiskAssessment';
		else if (!riskActions.showCalculateRisk.hide)
			primaryId = 'showCalculateRisk';
		else if (!riskActions.showChangeRiskDetails.hide)
			primaryId = 'showChangeRiskDetails';

		Object.keys(riskActions).map(id => {
			if (id !== 'changeRiskDetails' && id !== primaryId)
				if (!riskActions[id].hide)
					riskActions[id].hide = true;
		});
	}

        // Hides Calculate Risk button
	if (riskActions.showCalculateRisk)
		riskActions.showCalculateRisk.hide = true;


	api.setState('riskActions', riskActions);
}

 

Yeah This is also work but in the script I want the calculate risk button is hide only when standard change.

When it in other types this should be visible.
Thank you for your answer

 

Matthew_13
Kilo Sage

@SangareswarK - 

This is a common SOW gotcha.

The “Calculate Risk” button isn’t coming from a UI action or UX Form action. In ServiceNow, it’s rendered by the Risk Evaluation workspace component, which is why unchecking those options doesn’t do anything.

To hide it basically you need to go into UI Builder, open the Change Request experience, select the Risk Evaluation component, and control its visibility there for example by role or condition. Thumbs up and mark answered if this helps my friend.

Yeah I got it. Thank You for your response and it done by duplicate variant in UI Builder right.