XPages Query Save - need help

I need some help figuring out how to use the Query Save event in an XPage with a single Notes Document data source bound.

I can get the document to save but not to do anything with my pre-save calculations. I’m not even sure they’re running (I don’t think they are).

Here’s a snip of the source code:

		<xp:this.querySaveDocument><![CDATA[#{javascript:var doc = dataSourceName.getDocument();

doc.replaceItemValue(“Status”,1);

}]]></xp:this.querySaveDocument>

How do I get this to work? I’m confused for sure.

Also, any ideas about debugging server-side XPages code?

Subject: Debugging and referencing data source

Ken,

  1. debugging: I’m using plain javascript print() functions as in

print(“tell me what’s going on here”);

this will print your message to the server console as well as the good old log.nsf

If there are more elegant techniques I’d like to learn as well :slight_smile:

  1. referencing data source: your datasource is a known object within the xpage’s context. To get a field’s value, for example, I would call

var fullName = Person.getItemValueString(“fullName”);

where “Person” is the name of my data source.

BTW:

Assuming that your ds is named “Person” you also might be calling

Person.setValue(“Status”, 1);

Hope this helps

-Lothar

Subject: I think there was an article in the xPages Wiki about debugging.

Subject: What I figured out since the posting…

@Lothar: Thanks, I finally did find that in help. I haven’t found anything better so far.

@Erik: I’ll take another look in there but I didn’t see anything useful for debugging yesterday.

Xpages data source Query Save events never seem to happen. I don’t know if this is a bug or I’m doing something wrong.

When working with a server-side script i.e. submit button onClick event, it is important to know that you are working with the NotesXSPDocument object (and it’s properties/methods) NOT the back-end NotesDocument that will be saved later.

I found that, unlike Forms, if a XPage posts an empty field attempting to get that field’s value returns null so I wound up using the following conditional Javascript structure to get fields or return a default value:

var fldval=(dataSource.getItem(“myField”)) ? dataSource.getItem(“myField”) : “”;

Default values entered on a form that you use with Xpages do not get set on the Xpage. You have to set the default values in the Xpage field properties.

Subject: QuerySave and the save() method

The following SPR had been reported and fix in the 8.5.1 code stream: PHAN7MCC47: [FP?] The Save Document simple action doesn’t fire the querySaveDocument event

Is it how you’re saving the document? If you call the global save() method instead, or let a submit button do it, then the method should be called.

Subject: Yes, I started with a Save simple action.

After the simple action didn’t trigger the code I switched to server-side Javascript code, no simple actions.

I perform the work and call save(). This also doesn’t trigger the Query Save event, not that I needed to any longer.

Ken