This forum is closed to new posts and responses. Individual names altered for privacy purposes. The information contained in this website is provided for informational purposes only and should not be construed as a forum for customer support requests. Any customer support requests should be directed to the official HCL customer support channels below:

HCL Software Customer Support Portal for U.S. Federal Government clients
HCL Software Customer Support Portal



May 24, 2011, 9:41 PM
35 Posts
topic has been resolvedResolved

Open personal xPage document by default

  • Category: Other
  • Platform: Linux
  • Release: 8.5.2
  • Role: End user,Developer,Administrator
  • Tags:
  • Replies: 4
 Hello Forum,
 
In advance, thanks for the attention you'll take to my post.
 
I'm a xPages newbie and I was wondering how to open my home xPages on my person document on startup (if exists) 
 
In other words I created a xPage, on submit a document is created. When I start my xPage I want to view my personal document in edit mode, if it's my first login and no document exists in database I just want to open the default page to create one(same page, except that no data will be present) 
 
Personal document should be open according to the user currently logged on. 
 
I hope it's clear enough. 
 
Thank you very much. 
 
Chris 
May 25, 2011, 10:55 AM
54 Posts
Re: Open personal xPage document by default
I hope this helps to push you in right direction...
 
You can use e.g. the XPages' "beforePageLoad" event to do the check if a user profile exists or not. In case you need to open the new form to user, you can do a page redirect to the page you want to (see context.redirectToPage("yourPage") method).
May 25, 2011, 4:05 PM
47 Posts
Re: Open personal xPage document by default
 This is pretty straightforward. Make sure your xpage is the default launch target (Application Properties, Launch tab). On that xpage have a document data source with the default action being edit document, but compute the documentID. Have a view of your "personal" documents sorted by the user's distinguished name and to get the documentId do something like this:
 
var nve:NotesViewEntry = database.getView("personalsByName").getEntryByKey(context.getUser().getDistinguishedName());
return (nve == null)?null:nve.getUniversalID();
 
if the documentId is null, the datasource should go into createDocument mode.
 
Rich
May 26, 2011, 4:13 PM
35 Posts
Re: Open personal xPage document by default
Rami, Richard,
 
I big thank you for the precious help you gave me... 
 
Rami, you put me on the right way, I tested with code in the beforepageload of my xpage, I added the next piece of code to compute the documentID to open:

var db:NotesDatabase = session.getCurrentDatabase();

var vw:NotesView = db.getView('(vwU)');

var userDoc:NotesDocument = vw.getDocumentByKey(@Name('[CN]',@UserName(0)));

return userDoc.getUniversalID(); 

It works great, except that it generates an error when document does not exists, I then tried to add try / catch, without result...

===================== 
===================== 
 
Richard, 
You're right, your piece of code is just perfect... also much better using distinguished name!
I also try to understand : 

(nve == null)?null:nve.getUniversalID()

Means IF nve = null then null else nve.getUniversalID, I'm I right? this correspond to a shorter way of writing an if close... sorry for my lack of knowlegd, I just start with xPages and java.
 
Thank you very much! 
 
Best regards, 
 
Chris 
 
May 27, 2011, 3:50 PM
47 Posts
Re:conditional operator
Yes Chris, that is known as the conditional operator or ternary operator (because it is usually the only 3 operand operator) and is available in many languages. It is a very useful shortcut for if(clause){value1}else{value2}.
 
If you return null for the documentID for a data source, it will switch from edit to create document mode. 
 
Glad to be of some assistance, 
 
Rich 

This forum is closed to new posts and responses. Individual names altered for privacy purposes. The information contained in this website is provided for informational purposes only and should not be construed as a forum for customer support requests. Any customer support requests should be directed to the official HCL customer support channels below:

HCL Software Customer Support Portal for U.S. Federal Government clients
HCL Software Customer Support Portal