simon peter
simon peter

Reputation: 403

XPages dataTable control, compute visible

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

Answers (2)

Knut Herrmann
Knut Herrmann

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

Paul Stephen Withers
Paul Stephen Withers

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

Related Questions