current.setAbortAction(true) but capture a fields value

Iain6
Kilo Contributor

Hello ServiceNow forums,

I have added a business rule to our instance.

The purpose of it is to check that problem tasks are closed before the problem.

var rec = new GlideRecord('problem_task');
rec.addQuery('problem', current.sys_id);
rec.addQuery('active', true);
rec.query();
//If any of the tasks are active abort the submission
if(rec.hasNext()){
gs.addInfoMessage('Please close Problem Tasks first');
current.setAbortAction(true);


}

This code works fine but the problem I have is.

1. A user enters resolution information and then tries to close a problem with open tasks.
2. A message is shown saying they need to close tasks first
3. The user goes into a open task and closes it.
4. The user goes back to the problem record and has lost their resolution information.

Under these circumstances I would like what the user puts into the resolution field to be transferred into the work_notes.

Any help would be appreciated!

Thanks,
Iain

7 REPLIES 7

CapaJC
ServiceNow Employee
ServiceNow Employee

Haven't tested this, but maybe you could query for the current record with a new GlideRecord query, and update it. Something like the following:



var rec = new GlideRecord('problem_task');
rec.addQuery('problem', current.sys_id);
rec.addQuery('active', true);
rec.query();
//If any of the tasks are active abort the submission
if (rec.hasNext()) {
var me = new GlideRecord("problem");
me.get(current.sys_id);
me.work_notes = current.resolution_code; // not sure of real field name here
me.update();

gs.addInfoMessage('Please close Problem Tasks first');
current.setAbortAction(true);
}


Iain6
Kilo Contributor

Thanks CapaJC,

Unfortuantly this doesn't work. I think the current.setAbortAction(true); wipes out everything that comes before it.

Thanks,


Iain6
Kilo Contributor

If I put

var me = new GlideRecord("problem");
me.get(current.sys_id);
me.work_notes = current.close_notes;
me.update();

in as a business rule as itself it updates the worknotes. So the problem is with the current.setAbortAction(true); part of it

Should I maybe try some thing else instead of current.setAbortAction(true)?
Maybe manually set the values back to open and display a message?


CapaJC
ServiceNow Employee
ServiceNow Employee

I like that approach better. Allow the update, but have the business rule first set the state back to Open or whatever you want.

setAbortAction always gives an "invalid update" message that isn't very friendly. Better that you control the user experience and messaging.