0
votes

I've got a view control which opens an xpage. When the xpage opens, the beforePageLoad event fires. It checks to see if there are any attachments in a particular field of the document being opened and if there are, it returns list of the filenames. This was working fine. Then, I was asked to change what's displayed in one of the columns of the view. I added a variable to the view control's data section to access the row. I then added some javascript to the column to display the data differently. That worked and it displayed the data as wanted. However, when I now click on the link to open the xpage, when the beforePageLoad event fires, the code that's there now fails. It fails with this error at the starred line:

Script interpreter error, line=9, col=49: 'closureField' is null at
 [/Function_ReturnListOfClosureAttachmentNames.jss].ReturnListOfClosureAttachmentNames(CCEB1351591847CB85257E7C005EF68C)

function ReturnListOfClosureAttachmentNames(ltDoc ){
var closureAttachmentFileNames = "";
var thisLT = ltDoc;
var closureField:NotesRichTextItem = thisLT.getFirstItem("closeAttachments");
*>>> var eos:java.util.Vector = closureField.getEmbeddedObjects();<<<
var eosi:java.util.Iterator = eos.iterator();
while (eosi.hasNext()) {
    var eo:NotesEmbeddedObject = eosi.next();
    closureAttachmentFileNames = closureAttachmentFileNames +","+eo.getName();
}

return closureAttachmentFileNames;

}

I call this function from the beforePageLoad event and pass it currentDocument.getDocument(). I think I might have lost the document context after changing the column display data from 'view column' to 'computed value' but I'm not sure. Any ideas would be appreciated.

thanks!

Clem

1
Clem, can you include your beforePageLoad SSJS up until the point you call the function. I bet you are right. Also include view control's data section code.Steve Zavocki
Hi Steve... Well, it's just a one-liner: viewScope.closureAttachments = ReturnListOfClosureAttachmentNames( currentDocument.getDocument() );Clem
The data section of the view control just points to a Notes view. Nothing fancy. The view column code is the following and works perfectly: var status = rec.getColumnValue("statusOfIssue"); if (status == "Pending Closure" || status == "Pending Closure Assignment" || status == "Closed"){ return "LabWare Recommended"; }else{ return status; }Clem
Thanks for adding that. Have you tried getting the current document in your SSJS function as opposed to passing it in?Steve Zavocki
That all is very strange. Here is another idea: Get the current document's UNID in beforePageLoad (works only for saved documents) and assign to a var. Pass that var to the function as a parameter. In the function, obtain the document using that UNID. I can't see how you can go wrong here.Steve Zavocki

1 Answers

1
votes

Figured it out: When I assigned a variable to the view, when you click on a linked column in that view, it loads the current ViewEntry into the context and not a current document. So I put the unid of the doc from the selected ViewEntry in an application scope variable and returned it to the Document Id property when I open the xPage. I have to now update all my views but there aren't too many luckily. Thanks for working through this with me!

Clem –