Retrieve error message from a Business Rule

goswami_sudipta
Mega Expert

HI,

I have a BR which runs on CHG table and prevents a CHG record to get updated its state if that CHG's tasks are open. The BR also throws an error message stating the same. See below code which runs fine.

I am working on another script (for example, script name: ABC) where also I need to update CHG record, and during the update the above mentioned BR executes and the update does not happen. Now, I want to show the message - "Please close all the change tasks before making the change request as review" which is coming from the above mentioned BR in my script ABC.

Is there any way that I can show the error messages that are coming from a BR? Please help.

Thank you, Sudi

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

	var v_grChg = new GlideRecord('change_task');
	v_grChg.addQuery('change_request', current.sys_id);
	v_grChg.addQuery('state', '!=', '3'); // Closed Complete
	v_grChg.query();
	if (v_grChg.next()) {
		gs.addErrorMessage("Please close all the change tasks before making the change request as review.");
		current.setAbortAction(true);
	}
})(current, previous);
1 ACCEPTED SOLUTION

Hi Sudipta,

So this is how you would get last error message while record insert/update happens

grObject is the glide record object of the record

var errorMessage = grObject.getLastErrorMessage();

Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
Ankur

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

View solution in original post

5 REPLIES 5

Thank you, it worked. 🙂