Simple question about Scope Variables to JS

Hi I’m completely new to xPages and have what I believe should be a fairly simple question. I would like to “store” in a client side JS variable the value of a field immediately after the page is loaded.

What I’m trying to do is be able to keep track of what value a field is changed from and what the NEW value is when the page is resaved and then use the postSaveDocument event to run a notes agent that would write an audit history document that would become part of the main documents history. Basically so we would know at what date/time a user modified the value in a field and what they modified it FROM. So we could show something like this:

Field Firstname changed from “Joe” to “Bob” by “user”

My thoughts were if I could store all of the initial field values at the page load and then send them back at the pg. save my agent could then create all of the audit records.

Subject: Scoped Variables

Scoped variables are only server-side javascript, but then so is the postSaveDocument (or querySaveDocument) event.

The currentDocument variable gives access to the first NotesXSPDocument on your XPage, so if your XPage only pulls from one DominoDocument datasource, currentDocument will give you that. You can then loop through all items in the NotesDocument - currentDocument.getDocument() - and do viewScope.put(item.Name, item.Text). This will give you viewScope variables for each NotesItem. In queryPostSave you can loop through the items again using viewScope.get(item.Name) to compare the value.

Alternatively you could push values nto a viewScope variables from selected controls on your XPage using getComponent(componentId).getValue() and then check on save.

viewScope is best for this, because you’re never leaving the page.

Subject: Thank You…

Hi Paul,Thank you for the information. I’ll give it a shot…