Question

I'm looking to get the URLlink for a document. For the existing documents ( which are already saved and when I open them - I get the url with the UNID ) , it's OK, my problem is when I want to get the URL for a new created document - i don't get the UNID inside the URL. ( only, eg: http://myserver/ournsf/doc.xsp?action=newDocument, without the UNID )

My code is something like this:

if(docSource.isNewNote()){
        docSource.save();
    }
    empbody.appendText(context.getUrl().toString())

Thanks for your time!

Was it helpful?

Solution

context.getUrl() gives you only the current URL. It doesn't contain the documentId because you create a new document in your case.

You are looking for an URL that will open current document with current XPage. You can get it with:

var thisdoc = docSource.getDocument(true);
var url = facesContext.getExternalContext().getRequest().getRequestURL().toString() + 
          "?action=editDocument&documentId=" + thisdoc.getUniversalID());

OTHER TIPS

You can get the url of a new created document with:

document1.getDocument().getUniversalID()

Here document1 is the datasource name of your document. If you want to redirect to the new created document after a save, you can use this code in a navigation rule or add the following XML:

<xp:this.navigationRules>
    <xp:navigationRule outcome="xsp-success">
       <xp:this.viewId><![CDATA[#{javascript:return "XPageName?documentId="+document1.getDocument().getUniversalID()+"&action=editDocument"}]]>      
    </xp:this.viewId>
    </xp:navigationRule>
</xp:this.navigationRules>

Where XPageName is the name of the XPage.

You could use the postSaveDocument event of your datasource to calc the URL from the UNID like

var url = "page.xsp?action=openDocument&documentId="+document1.getDocument().getUniversalID();
document1.setValue("url", url);
document1.save();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top