Display a message when Related List New button is clicked

Community Alums
Not applicable

For HR Form there is related list called Child Cases, which has two buttons New and Edit. Whenever Record is in Resolved state and this New button is clicked, I want to display an Info Message that " New child case cannot be added because state is resolved please change it to Work In Progress first"

Let me know how this is possible oror provi code if any.

1 ACCEPTED SOLUTION

Hi Sindhu,

To show the error message on same page use the following. Please ignore the previous solution:

Display BR: You need to write display BR for HR table and edit the script accordingly

(function executeRule(current, previous /*null when async*/) {
	if(current.state == 7) {
		var incidentURL = current.getLink();
		var instanceName = gs.getProperty('instance_name');
		if (instanceName && incidentURL) 
			g_scratchpad.incidentURL = 'https://'+ instanceName + '.service-now.com/' + incidentURL;
	}
})(current, previous);

UI action:
Name : New
Table : Incident //You can creat this UI action on Child Cases
Action name : sysverb_new_custom
Client : Checked
List banner button : Checked
Onclick : checkIncidentState();

function checkIncidentState() {
	if (g_scratchpad.incidentURL) {
		g_form.addErrorMessage('You cannot insert record for Closed incident');
		action.setRedirectURL(g_scratchpad.incidentURL);
	}
	else {
		gsftSubmit(null, g_form.getFormElement(), 'sysverb_new');
	}
}

Using this you will get the error message on your HR form. Please let me know if you face any issue in this.

Please note that you might need to write another UI action to redirect the page if the record is not is resolved state and called it in else part

Please mark it correct/helpful, if it resolves your problem.

Thanks

View solution in original post

5 REPLIES 5

Vijay Pawar3
Tera Contributor

Hello,

       Better than that.  You can hide the New button for resolved incidents by updating the 'Create child incident'  UI Action. Add condition to not display the UI action for  resolved incidents.

This is for incident, you can use the same login for your use case.