update in a display business rule

brumiou
Mega Guru

Hi,

I have a request from the business :
they want that if the service desk enter a comment, the record appears in the list with a specific color (that's easy)
But then, if someone from a specific group opens the record, this should put the record color to normal.
It means I have to update the record when the user opens it.

I tried to do that with a display business rule, but if I do a current.update() when the users open the form, he gets a blank screen.

I tried to use gs.setRedirect, but without result.

Have you any idea on how to update a record when someone opens the form? Without any action from him?

Thanks a lot

rgds

Xavier

10 REPLIES 10

CapaJC
ServiceNow Employee
ServiceNow Employee

From a purist standpoint, I'd have to say avoid updating an actual record before viewing it. I can't explain why it seems wrong, but it does. Just like calculated fields seem wrong.

However, if you can set a g_scratchpad variable in a display BR, and react to that in an onLoad client script to do something visual, I think I'd prefer that.

Then again, I'm not living in your instance 🙂 It's always easier to be judgemental from a distance.


pr17
Kilo Explorer

I wish you could give some reasoning behind your purist view as now you have put me in two minds regarding this implementation. I would also accept a workaround to achieve the functionality, i.e. set a flag field to true/false when the record is accessed. Please note, I am not changing a field that is available on the form to the user, so this is kind of async display business rule 🙂

With regards to the g_scratchpad option, I wanted to utilise display BR so I do not update a record in client script and avoid a server call. I have done this before with a client script before display BR existed in SNC since I didn't have an option back then.

I welcome your view though, will surely be thinking about the things that this might break/hinder with back of mind and also discuss with others, cheers.


CapaJC
ServiceNow Employee
ServiceNow Employee

Nah, I retract my objection. If a "before display" update does the trick, it's a simple and effective one. I suppose one risk would be that the update might trigger an email notification, and the update would run business rules and audit a change just for viewing the record, but that might not be of concern. And you could always make the update with workflow off and not update the system fields like sys_updated_on.



gr.setWorkflow(false);
gr.autoSysFields(false);


pr17
Kilo Explorer

Nice to have endorsements from a few people on a solution, so thanks for that.

With regards to disabling execution of workflows to avoid notifications, I was suggested that internally as well and I have done that bit (


gr.setWorkflow(false);
) just to future proof the solution.

Left the sys_audit_fields as it is though since I thought it makes sense to see who is resetting a flag and also because it makes it much easier for the client to test the solution.


I would also add a check for field=true in the display rule so you aren't adding an extra query and update for every record load. Think that would helps the purists sleep at night.