display Business rules and some issues

Andrew Pishchul
Giga Expert

I just noticed a bit strange behavior:

1. Create onDisplay business rule on Incident table,which sets Short Description to 'Hello' (this runs for any incident every time):

current.short_description = 'hello';

2. Open any existing incident   - you'll see 'Hello' in a short description

3. Change anything on a form, but don't touch short description and save the incident

4. ...what would you expect to happen?

'Hello' forced by a business rule to Short Description has not been saved - you can check that in the list of incidents.

This affects all versions... did I miss something on how ondisplay business rules work?

6 REPLIES 6

hadyndickson
Mega Expert

Sounds like ondisplay business rules only effect the display of the record in the client after the data is retrieved, which seems understandable. But I was under the impression that all data on a glideform was sent back to the server on post, meaning it should save the new value in your form server side if it has changed since last time. Maybe when the form is displayed the html form element value is not actually set? Seems a bit far fetched to go to the trouble to do that.


Deepak Ingale1
Mega Sage

Hi Andrew,



Display business rule executes before onLoad client script and used to pass Server side information to client side scripts via g_scratchpad global object variable.


To save record, you will have to either go for Before or After business rule



Business Rules Best Practices - ServiceNow Wiki


Hi Deepak,


I'm not trying to save the data by Dispay business rule, I just want to put some data in a field once the form is loaded - that works fine with a display business rule.



The problem is that once you put the data in a filed (by a display business rule) and then click Save or Update button, the data will not be saved.


Hi Andrew,



When a record is updated, system checks for "changes" on every field (according to my investigation) and if "changes()" returns false it is not part of SQL UPDATE statement (see it via debug SQL). It means that display business rule does not set "changes" flag on the field and so it is not updated. Notice that this works when it is new record since in such case all fields are part of the SQL INSERT statement - this means you can use display business rule to set defaults for new records but not for already existing records.



I don't know what is your use case, but I guess that for existing records, you could use either on load client script to set a value (and you can just send the data to client via g_scratchpad).



Cheers,


Dominik