Background: I’m trying to set a global variable in server-side javascript, with the aim of being able to check that variable in several XPage view columns. The variable only needs to exist for the duration of one request, because I’m only using it for column rendering.
The following is part of a server JS library (with line numbers copied from stack trace):
1: var bwConfigView=null;
2: var bwConfigDoc=null;
3:
4: function bwViewLoad()
5: {
6: requestScope.showPersonAltName=bwPersonShowAltName();
7: requestScope.showPersonAltAddress=bwPersonShowAltAddress();
8: requestScope.showOrgAltName=bwOrgShowAltName();
9: requestScope.showOrgAltAddress=bwOrgShowAltAddress();
10: }
11:
12: function bwGetCfgDoc()
13: {
14: if (bwConfigDoc!=null) return;
15: bwConfigView=database.getView(‘v-config’);
16: bwConfigDoc=bwConfigView.getFirstDocument();
17: }
18:
19: function bwPersonShowAltName()
20: {
21: bwGetCfgDoc();
22: var fVal=bwConfigDoc.getItemValueString(‘UI_PersonAltName’); //Error occurs here
23: if (fVal==null) fVal=‘’;
24: return (fVal==‘1’);
25: }
In the beforePageLoad event of an XPage, I have the following:
bwViewLoad();
When attempting to load the XPage in a browser, the following error message appears:
Error while executing JavaScript action expression
Script interpreter error, line=22, col=30: Exception occurred calling method NotesDocument.getItemValueString(string) null
I think it’s saying that bwConfigDoc is null, but that shouldn’t be the case. Can someone explain why this fails, and how I can make it work?