We have documents containing “key” of some referenced document. There is reason we don’t use UNIDs. I want to initialize data source by this key value. So in Document ID property I write script to open view, look up specified document and use looked up UNID to initialize data source.
I think this is not optimal solution.
Question: is there a better way to initialize document data source based on key value?
Sample code:
@DbLookup("", "view", "key", 1, '[RETURNDOCUMENTUNIQUEID]');
Looking up the document’s UNID by key in a view is probably indeed the best way to do it. However, you could speed up repeated calls a bit by writing a managed bean to act as a cache. If, for example, you wrote a Java class that implements java.util.Map, stub out most of the methods, and implement a .get(…) method that takes the key as a parameter, you could reference it like (assuming you call the bean “DocKeyManager”):
<xp:dominoDocument … documentId=”${DocKeyManager[someKey]}”/>
That way, you could cache the value from the .get(…) call and not have to hit the database each time, and it’d also let you change the lookup algorithm later.