Refreshing the xpage document & showing the computed fields immediately without closing & reopening the xpage document - xpages

I am working with xpages and need a unique number to be generated for each document. After saving the document, I want the user to be on the same page viewing the generated number. For this I have used the a action group on the submit button - 1) first action is a simple action which is saving the document. 2) Next action is script editor where I am calling my number generation agent 3) The last one is a simple action which is changing the current document mode from Edit to Read so that the user is still on the same xpage document after saving. But I see that the document is saved properly and also changed to read mode but I cant see the number generated. But if I close the document & open it again I see that the number is generated. I want this number to be shown without closing & reopening the document. Any help is appreciated.

If you're updating the backend Document datasource, you'll need to either fully reload the page or close and re-open. Try setting the unique reference on the dominoDocument datasource and re-saving that. Alternatively, build the relevant URL to the XPage with the relevant documentId parameter and redirect accordingly.

You can put a Full Upload at your onClick event or a partial Upload.
With the partial Update will update just one element of your page, if your computed fields are inside this element they will be updated.
http://i.stack.imgur.com/g0DA7.png

Related

Why is the wrong form opening when I click the doc link I created from a SSJS function?

Ok, this is weird. I created an xpage input form. After the form is filled out, a document is created. I then create an email to notify people that the document has been created. I drop a doclink to the newly created document in the body of the email. During testing, I noticed that when I click the link in the email, the wrong Notes Form is opened. Instead of the 'TrainingRequest' form displaying the fields, the form 'Feedback' opens up instead. Here's what I checked:
- On the xpage data section, the 'form' is set to 'TrainingRequest'.
- When I open the document via the doc link, the field 'form' has the value 'TrainingRequest', which is correct. Yet it's displaying the 'Feedback' form.
- When I check the other field properties of the document, all the correct fields from the 'TrainingRequest' form are there and populated correctly.
- When I open the document via the view, the correct Notes form 'TrainingRequest' opens.
- There is no default form in the database design.
Has anyone seen this before?
thanks
clem
Doc links are always created using the default view of your application. If there is a form formula in this view then this overrides the form in the document. Remove the form formula of the default view and it works.
I almost NEVER use form formulas in my application because of the side effects.
Source code would be useful. But initial best guess based on what you're saying is you have two datasources on the XPage, neither have ignoreRequestParams set, so you're editing the same document with both data sources. ignoreRequestParams missing will ignore any properties you define.

XPage not syncing properly with backend data on partial refresh

I have an XPage that displays fields in a document. I also have the ability to pop out a new window that displays those same fields. I'm implementing a document locking scheme so that the two instances can't cause conflicts (and this is how I'm testing it).
A problem I've run into is that when the user edits the document in the pop out and saves it, a partial refresh of the panel containing those same fields in the original page doesn't show the updated data.
The save in the pop out was successful, and I can see in the Notes client that the document does indeed have the new value, but the original page simply won't show the new value. A complete page refresh using the reload button in the browser works, but I'd like to trigger this programmatically and as quickly as possible, hence the partial refresh.
Does anyone know what is going wrong? Is the NotesXspDocument in the original page getting out of sync with the backend document? I read about document1.getDocument(true), but that doesn't seem to do anything.
(As usual, I can't supply source code unfortunately....)
Once the NotesXspDocument is loaded with the XPage, a partial refresh does not update the xspDoc from the back-end DB, but from the in-memory DataSource.
You will need to refresh the XPage:
Reload the url from browser or in ssjs with a context.reloadPage()

Multiple data sources in XPages

I have 2 xpages that interact together. The first acts as a homepage and allows the user to create a new document and fill out some basic header information. The button to create the new document, sets a sessionScope var with the NoteID. It then saves document1 and opens the same document using another xpage.
The second xpages is bound to document1, and uses the sessionScope to edit the document. This xpages contains and editPanel bound to document2. I want to create a child document to document2. This works but what happens is document1 is also saved as conflict. It is also saved as a second main document.
I DO NOT want to save document1 at all, but can't seem to prevent it. The button that creates document2 uses the simple action save document, and specfies document2.
HELP, I have tried everything, and have been stuck on this for 2 days.
Thanks!
Steve
To bind to multiple datasources, on your XPage, under Properties expand Data and set "Ignore Request Params" to TRUE
If you change the type of your buttons, to a simple button instead of a submit button, and handle the doc.save() yourself should solve your problem.
The Save Document simple action accepts the name of the data source to save as a String argument. If supplied, it will only save that specific data source.

Automatically open document when only one document is listed in repeat control

I have a repeat control for a domino view which displays the results from a search field.
As you type more characters into the search field the number of items in the list is reduced. If/When the the list only contains a single item I would like to open item automatically, without having to click the link.
Any ideas are appreciated.
Edit: after some very interesting responses, here are some screenshots
I have 3 elements on the page, a searchbar, a repeat control and a form:
When I start typing in the search bar, the repeat is refreshed with every keystroke:
the list is reduced, typing the next character ...
again the list is reduced, only 2 left, typing again....
Only one left, now it would be time to open the document in the form ..... without clicking the link.
I've tried several events on the page, but it seems that I could not find the one that will allow me to "select" the document and display the data in the form.
It seems that it's not as simple as I thought
Since you want to open the link automatically I don't know if I would try to base it on the getRowCount() of the repeat itself. You don't want to even get that far right? you just want to go to the single document.
I would put a function in beforePageLoad event maybe. Not totally sure which event but I'd try that first. Use SSJS and do a lookup that would basically return a collection of what the repeat would show. If the collection count = 1 then get your destination from that entry and do your redirection from there.
That what I would try at least. Interesting scenario!
Now that I see the screenshots this might be easier then you think and I have already implemented something similar on an internal application that I have built. It does rely on the fact that each entry in the list is 100% unique.
First of all you will need to bind the search field to a scoped variable and the onchange/onkeypress event will need to perform a partial refresh of a panel that contains both the list and the document portion of the page.
For the list the link on each item should set the value of the same scoped variable used in the search box and clicking the link should be set to run a partial refresh of the document area.
For the document area you will need two panels, the first panel will only display if there is no matching document and the second panel will only display if there is a matching document, you can do this in the rendered section by writing some ssjs that grabs a handle to the db/view and does a dblookup and returns either true or false if the document exists depending on panel your dealing with.
With this setup, when somebody clicks a link or fills out the searchbox the scoped variable will contain a value, the document panels will then check to see if this is a unique value in the view in the db and update themselves to either display the 'no document' panel or the 'document' panel accordingly.
You could add a evaluation script to the entry of your repeat control which checks the size of your repeat control using the method getRowCount() from the component. If this is 1 you could execute a context.redirectToPage("yourpage.xsp?id=yourid",true) this forces the current page to send a redirect request back to the browser and therefore redirects you to the correct page.
All you need to know is which xpage you need to open and which parameters you should use. But these could be retrieved from the content you are iterating over.

Dialog Control Cannot See Second Data Source on the XPage

I have a custom control with a field where the user will enter a document ID (not a note ID or UNID, just a unique number). This data source is named document1. When they exit the field, I perform a lookup and display either the document with that ID or a new document in an extlib Dialog control (data source bundleDoc). When bundleDoc is saved, I want to update a log field on document1 to indicate that a bundle document was added.
I can save bundleDoc and close (hide) the dialog but the code in my Save & Close button in the dialog can't "see" document1. I can't refer to it using document1.getItemValueString or by getComponent. The getItemValueString returns and empty string and getComponent throws an error because the return value is null.
I would have posted an image to help visually but I don't have enough reputation yet. :(
What am I missing? Shouldn't I be able to get to document1 from the dialog control since it is on the same XPage?
UPDATE: Two fields on the dialog form have computed default values that use getComponent to get their values from document1. So, at least when the dialog is loaded, it can see document1. Also, bundleDoc is not defined as a data source for the dialog control. I will try that tomorrow to see if it makes a difference.
UPDATE 2: Still not enough reputation to post a picture, but here is some code. This is one custom control that contains a dialog control. document1 is defined as the data source for the custom control and bundleDoc is defined as the data source for the panel in the dialog control that contains the table of fields for the bundle document.
The BundleID field in the dialog control has a computed default value using this:
if (bundleDoc.isNewNote()) {
getComponent("inputBundleID").getValue();
} else {
bundleDoc.getItemValueString("BundleID");
}
The formula for StorageLocationID is similar except that the component is inputStorageTrayID.
This is the code in the Save & Close button:
bundleDoc.save();
var newArr = new Array(document1.getItemValue("WorkLog"));
newArr.push("Added bundle " + document1.getItemValueString("BundleID") + " - " + session.getCommonUserName());
document1.setValue("WorkLog",newArr);
document1.save();
getComponent("dialog1").hide();
The error happens on the document1.save line but it does not get the BundleID from document1 (I set a sessionScope variable to the value of newArr and it showed 'Added bundle - Anonymous'.
It depends on where you have added the datasources. If document1 is set as the datasource of custom control 1 and bundleDoc is the datasource of custom control 2 you can't access them outside of the custom control they're defined in.
If you add document1 as the datasource of your custom control and create the xe:dialog control (containing a panel with the bunleDoc datasource) in the same custom control you should be able to access document1 (and update/ save it) from a button on the dialog.
I think the problem was initially caused by caching issues because it started working the day after I posted the question.
However, I had to do one more thing to get the page to work the way I wanted to. This is the XPage in Designer:
To write a value from the Save & Close button back to the WorkLog field, I had to save the document1 data source before opening the dialog. Then document1 was recognized throughout the Save & Close code and it was saved properly at all times.

Resources