Reputation: 1660
On save of a document I'm running SSJS that is doing a .save() and then I am wanting to include the document link (URL) in the body of a notification email that gets sent by using context.getUrl().
This works for documents that are already saved because it has the doc id in the URL when doc gets opened, but not for new docs. Is there a way I can accomplish this for new documents that do not have their ID yet?
Upvotes: 1
Views: 2418
Reputation: 20384
Another possibility: if you have a form behind the document and the property "open XPages instead" you can use the http://server/database.nsf/0/universalid
syntax. When you have an unique identifier in your document you also can use a view sorted by that identifier and use http://server/database.nsf/sortedview/sortkey
. With the sorted view you could predict the URL before saving.
Upvotes: 1
Reputation: 21709
You have to construct the URL yourself since (as you already know) the context.getUrl() method can not be used.
So after your .save() you could do something like the following:
var docUrl = context.getUrl().toString().split(view.getPageName())[0] + "/" + database.getFilePath() + view.getPageName() + "?action=openDocument&documentId=" + document.getNoteID();
The context.getUrl().toString().split(view.getPageName())[0]
part should give you the hostname and database filepath according to David Leedys xpagescheatsheet.com URL test. I then add the current XPage name and the openDocument and docid parameters.
Upvotes: 2