Reputation: 403
I am trying to learn how to do a computed visible property on a dataTable to hide an field/ row if status is enabled or disabled.
below code is what i have used but keep getting error
var userName=rowData.getColumnValue("userName")
var status:NotesView = database.getView("(UserProfile)");
var doc:NotesDocument = status.getDocumentByKey(userName);
var active = doc.getItemValueString("Status")
if(active == "Enabled") {
return true
}else{
return false
}
Upvotes: 0
Views: 246
Reputation: 30960
Put your code into a try-catch-block as you want the part only be visible if user is in view "(UserProfile)" and has a certain status:
try {
var userName=rowData.getColumnValue("userName")
var status:NotesView = database.getView("(UserProfile)");
var doc:NotesDocument = status.getDocumentByKey(userName);
var active = doc.getItemValueString("Status")
if(active == "Enabled") {
return true;
} else {
return false;
}
} catch (e) {
return false;
}
Upvotes: 1
Reputation: 15729
Is this failing on page load or during a partial refresh? If the latter, you could be hitting the problem that I mention here http://www.intec.co.uk/dataviews-and-nested-repeats/. A partial refresh is a number of server-side phases, during which the server-side map of the page is retrieved, values from the browser applied, and the contents of the Data Table recalculated. During the early phases, the variable rowData
will be null, which means doc
will also be null.
Using a logging mechanism like XPages OpenLog Logger will capture the stack trace which will include the phase it's failing in.
Use view.isRenderingPhase()
to only run the code in the Render Response phase (the phase that writes HTML back to the browser). It will avoid phase-specific issues and also optimise the performance. If it's rendered property, that's the only phase you need to compute the value in ;-)
Upvotes: 1