Live form updates trigger onchange scripts - How to prevent?

chris_f
Kilo Expert

and cause mayhem

Does anyone know if there is a useful method (passed to the one change script, perhaps), that I could use to see if the update to the field was by the user (manually via his web browser) or due to the livefeed updating such a field (in which case, we may not trigger the script, and just return early).

Currently the following occurs:

User 1 and User 2 view an incident. User 1 updates and saves the record.

User 2 viewing this record, see's this live update ("User 1 has modified this field value") beneath a field. This field has a "on_change" script on it, which is then triggered which sets work notes to mandatory >> Now user 2 must fill in work notes, or, have to reload the form, then redo whatever changes they may have made.

Not ideal....   [ User 2 shouldn't be forced to justify the form change, but is, because the web page just sees something changed ].

Thus, i'd like to make a script adjustment of:

if (userUpdatedField != me)

        return;

//Else continue to run script, as the user made the change so all is well.


Thanks all

1 ACCEPTED SOLUTION
3 REPLIES 3

LaurentChicoine
Tera Guru

Hi Chris,



I looked at the code behind the live form update and I found that the script is setting a g_form attribute before modifying the value on the field and setting back that attribute when it's done updating the form.



So the condition you are looking for is:


if(g_form.isLiveUpdating())


        return;


Just found that it is in fact documented so I did not need to go find this in the code. https://developer.servicenow.com/app.do#!/api_doc?v=istanbul&id=r_GF-isLiveUpdating


Hi Laurent,


Apologies, I reviewed the API and clearly missed that method!



That does the job! Nice.


Thank you