Issues with gr.isActionAborted()

kyrresc
Tera Expert

Hello,

I am having issues with gr.isActionAborted(). Even though my update does NOT go through, gr.isActionAborted() returns false. Weirdly, when logging gr.update(), it returns null... I logged it like this. This code snippet is placed within an if-statement checking that grTask.isValidRecord()

grTask.update();
gs.info("grTask: " + grTask.update());
gs.info("is action aborted?" + grTask.isActionAborted());
1 ACCEPTED SOLUTION

Hi,

see image below

1) I have 1 Before BR which blocks the update

So isActionAborted() -> gave true

find_real_file.png

find_real_file.png

I deactivated the BR and

So isActionAborted() -> gave false

find_real_file.png

Regards
Ankur

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

View solution in original post

14 REPLIES 14

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

please share complete script

Regards
Ankur

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

var task_id = this.getParameter('sysparm_task_id') + '';
		var billing_type = this.getParameter('sysparm_billing_type') + '';
		var billable = this.getParameter("sysparm_billable") + '';
		var billing_reference_1 = this.getParameter("sysparm_billing_reference_1") + '';
		var billing_reference_2 = this.getParameter("sysparm_billing_reference_2") + '';
		var billing_reference_3 = this.getParameter("sysparm_billing_reference_3") + '';
		var chg_task_type = this.getParameter("sysparm_chg_task_type") + '';
		
		gs.log('server - update task: ' + task_id);
		gs.log('server - update billing type: ' + billing_type);
		
		var bSuccess = true;
		var grTask = new GlideRecord('task');
		grTask.get(task_id);
		if(grTask.isValidRecord()){
			if (grTask.getValue("sys_class_name") == "incident" || grTask.getValue("sys_class_name") == "sc_req_item") {
				grTask.setValue('u_billable_task',billable);
			} 
			else if (grTask.getValue("sys_class_name") == "change_task") {
				grTask.setValue("u_billing_type_task",billing_type);
			}
			else if (grTask.getValue("sys_class_name") == "change_request") {
				grTask.setValue("u_billing_reference_1",billing_reference_1);
				grTask.setValue("u_billing_reference_2",billing_reference_2);
				grTask.setValue("u_billing_reference_3",billing_reference_3);
				if (chg_task_type == "standard" || chg_task_type == "standard_tasks") {
					grTask.setValue("u_billing_type_task", billing_type);
				}
				else {
					grTask.setValue("u_billable_task",billable);
				}
			}
			gs.info("is action aborted?" + grTask.isActionAborted());
			grTask.update();
			gs.info("grTask: " + grTask.update());
			gs.info("is action aborted?" + grTask.isActionAborted());
			if(grTask.isActionAborted()){
				bSuccess = false;
			}
			}
		gs.log('server - returning: ' + bSuccess);

Hi,

isActionAborted returns false which means your grTask update is working fine.

If it returns true, then it means that your operation is aborted.

Did you check record got successfully updated or not?

if it gets updated properly it means that function would return false

if record not gets updated then that function would return true

Did you check any before update BR is restricting the update operation?

Regards
Ankur

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