xpages Trying to get document parentdoc is returning null error

邮差的信 提交于 2019-12-12 01:29:48

问题


I am trying to get the parent document of a new response document so I can duplicate the functionality of form inheritance in xpages. The following is my code and the error being returned:

Error while executing JavaScript action expression
Script interpreter error, line=3, col=60: 'parentDoc' is null
JavaScript code

   1: if (document2.isNewNote()) {
   2: var parentDoc:NotesDocument = database.getDocumentByID(document2.getParentId());
   3: getComponent("immediateParentSubject1").setValue(parentDoc.getItemValueString("Subject"));
   4: }

回答1:


I usually use a dataContext and getParentDocumentUNID() when I need a handle on the parent document for the variable "document". You can use this for a new document (not saved yet):

<xp:this.dataContexts>
    <xp:dataContext var="parentDoc">
        <xp:this.value><![CDATA[#{javascript:
            try {
                if (document.isResponse()) {
                    return database.getDocumentByUNID(document.getDocument().getParentDocumentUNID());
                } else {
                    return "";
                }
            } catch(e) {
                return "";
        }}]]></xp:this.value>
    </xp:dataContext>
</xp:this.dataContexts>

You can then use parentDoc in other controls and do parentDoc.getItemValueString("Subject") etc.




回答2:


datasource.getParentId() does not return the NoteID as you might expect. It returns the UnID and that's why you need to use database.getDocumentByUNID as Per is doing.

Another way is to get the parent UnID from the URL:

param.get("parentId")

Consider also looking up the parent subject whenever a child is opened instead. That way it is stored only in one place which is always a good thing.



来源:https://stackoverflow.com/questions/14713877/xpages-trying-to-get-document-parentdoc-is-returning-null-error

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!