I have an XPiNC locally replicated (not on server) application with a data source on a custom control that looks like this:
<xp:dominoDocument var="document1"
formName="demo"
databaseName="#{javascript:getDemoData();}"
action="openDocument"
documentId="#{compositeData.unid}">
</xp:dominoDocument>
In my JavaScript I have the function:
function getDemoData() {
return "12345678:9ABEDEFF";
}
That return the replicaID of the database containing my data (In the actual code it isn't hardcoded, but read from configuration, but that's not the question here).
To my best knowledge (which might be faulty), I can't specify a server name when providing this replica syntax. This turns out to be a game of chance. Sometimes the database opens on the server, sometimes on the client. I presume that's based on desktop8.dsk and which replication icon is stacked on top (?).
My question:
How can I ensure, if a local replica is available, that the local replica is opened first?
Clarification:
NotesDatabase.getFilePath() on a local machine returns the absolute filepath of that file (on a server it is the relative). Once you use dirlink files, then the absolute path doesn't resemble the relative path at all.
Sample: C:\Notes\Data
with a development.dir
file containing E:\customers\stuff
would require to add as path development\shiny.nsf
but NotesDatabase.getFilePath
would return E:\customers\stuff\shiny
. So it seems (?) I have to read the registry to find the data path from the Notes.ini, then check it against the filepath and when there is no match go fishing for the dir files until I find a match.
Open to better ideas :-)
Update:
Changed code based on session.getDbDirectory()
to better solution based on db.openByReplicaID()
like suggested by Christian. Added test @ClientType() != 'Web'
.
This code will find the database's local replica and return "!!filePath"
if the database exists locally. Otherwise it returns the replicaId
.
<xp:this.databaseName><![CDATA[#{javascript:
var replicaId = getDemoData();
if (@ClientType() != 'Web') {
var db = session.getDatabase(null, null);
try {
if (db.openByReplicaID("", replicaId)) {
return "!!" + db.getFilePath();
}
} catch (err) {
}
}
return replicaId
}]]></xp:this.databaseName>
This code works for XPiNC and for browser although it will look for local replica only for XPiNC. Code can run in a local database or database on server.