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

Mahendra RC
Mega Sage

Hi Sindhu,

you can write a display BR and onload client script on your child cases table. I have written on incident table as shown below:

I am using Parent Incident and Child incident case, where user will get the Error message displayed when user click on 'New' button present in 'Child Incidents' tabs related list to created child incidents for Incident whose state is 'closed'.

User will not get any error message if user opens the existing child Incident (INC0010192 in this case). User will get error message if user tries to create new Child incident.

 

Display BR :
(function executeRule(current, previous /*null when async*/) {

     if(current.parent_incident.state == 7 && current.isNewRecord()) {
         g_scratchpad.new_incident = 'not allowed';
    }

})(current, previous);

onLoad Client Script:

function onLoad() {
    if (g_scratchpad.new_incident == 'not allowed') {
          g_form.addErrorMessage("New Record cannot be created");
    }
}

find_real_file.png

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

Thanks

Hi Sindhu

Is your issue resolved?

 

Community Alums
Not applicable

Hi Mahendra,

I tried for incident form it is working but how can I display error message in same page as soon as button is clicked instead of going to different page?

 

Regards,

Sindhuja

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