The CreatorCon Call for Content is officially open! Get started here.

Updating a boolean field after an update is performed

tsam
Kilo Explorer

Hi -

I have a boolean field that I need set to false anytime a form is updated, copied or saved. I have tried using business rules and UI policies to no avail. Sample script I am using is:

------------------------------------------------------------
var review = g_form.getValue('u_reviewed');

if (review == 'true'){
g_form.setValue(u_reviewed == 'false');
}
--------------------------------------------------------------
I have also attached a screen shot of the UI condition here.

Can someone please point me in the right direction?

Thanks.

5 REPLIES 5

zachkenyon
ServiceNow Employee
ServiceNow Employee

I would probably do it as a Before business rule on Insert or Update.

Condition: current.u_reviewed==true

Script:
current.u_reviewed=false;


That will make it so if the item is inserted or saved and the Reviewed box is checked, it will get unchecked.

However, that makes it so you can't ever check that box - every time it gets checked and saved, it gets automatically unchecked again. I'm not sure exactly what your goal is, but you'd probably want to refine that condition so that it only triggers when you want it to uncheck.

If you want it to uncheck only if the Reviewed box wasn't checked in the current update, add: && !current.u_reviewed.changes()

If you want it to uncheck only for people without a particular role, add: && !gs.hasRole('role_name')

Hope that helps.


Thanks for your response.

I am trying to uncheck the reviewed button when users update anything on the form, so the form will have to be reviewed again by the admins and then the admins can re-check the reviewed button.

So I was thinking that, the rule should uncheck the reviewed button "AFTER" an update or copy is done after the reviewed button was first checked.

What will be a good way to get this accomplished?


I have also tried using a client script for this purpose but it's still not working. Please see attached. :-((


zachkenyon
ServiceNow Employee
ServiceNow Employee

I wouldn't recommend using client scripts or UI policies for this kind of thing, it'd be better off as a business rule.

The screenshot I attached above should work. You'd need to make sure that only the designated administrators have the ability to check the "Reviewed" field.

When: Before, Insert, Update

Condition: current.u_reviewed==true&&!current.u_reviewed.changes()

Script: current.u_reviewed=false;


Example of usage:

User1 submits the form, reviewed is false. Nothing happens (condition current.u_reviewed==true not matched)

Admin1 reviews the form, sets Reviewed to True, submits. Nothing happens (condition !current.u_reviewed.changes() not matched)

User2 goes back in, makes changes to the form (but not to the Reviewed field), submits. Reviewed is set to False, because the form was updated, Reviewed is True, and Reviewed did not change.


You could instead make a timestamp GlideDateTime field that would record when it was reviewed, and base whether to uncheck the box on the time since that review, but from what you describe it sounds eaiser to do it the way I described.

I built a quick solution along those lines on the Demo11 instance on the Problem table:

https://demo011.service-now.com/

> Created "Reviewed" boolean field on the Problem form
> Set security "write" access to Admin only for that field
> Created business rule "Uncheck Reviewed" as in the screenshot above

Test that out and see if that's kind of what you had in mind.

Let me know if that doesn't work out for you.