Search code examples
xpages

How to pass variable from CSJS to SSJS in read mode


I want to be able to prompt the user for a comment and then be able to send this variable comment in an email. However, I'm unable to pass that variable from CSJS to SSJS. My document is in read mode.

Here is a sample button code where I can't seem to pass my comment.

Does anyone know how to do this?

Thanks in advance :)

<xp:panel readonly="false">
    <xp:inputHidden id="inputHidden1" value="#{viewScope.tester}">
    </xp:inputHidden>
</xp:panel>

<xp:button value="Reject" id="button7" style="margin-right:5.0px"
save="false">

<xp:eventHandler event="onclick" submit="true" refreshMode="complete">
    <xp:this.action>
        <xp:actionGroup>

            <xp:executeScript>
                <xp:this.script><![CDATA[#{javascript:var doc:NotesDocument = currentDocument.getDocument();
doc.replaceItemValue("status", "0"); 
doc.save();
database.updateFTIndex(false);

var comment = viewScope.tester; /* HOW DO I GET COMMENT FROM CSJS TO HERE */

var ndoc = database.createDocument();
ndoc.appendItemValue("from", "tome@somewhere.com");
ndoc.appendItemValue("SendTo", "someone@somewhere.com);
ndoc.appendItemValue("subject", "My Subject");
var rti:NotesRichTextItem = ndoc.createRichTextItem("Body");
rti.appendText("Reason:" + comment + "\n\n");
ndoc.send()

}]]></xp:this.script>
            </xp:executeScript>
            <xp:openPage name="/mainpage.xsp"></xp:openPage>
        </xp:actionGroup>
    </xp:this.action>

    <xp:this.script>
        <xp:executeClientScript>
            <xp:this.script><![CDATA[
var comment = XSP.prompt("Please enter a comment:");


XSP.getElementById("#{id:inputHidden1}").value = comment;


/*
XSP.partialRefreshGet("#{id:computedField1}", 
{
params:{"para1":"1", "para2":"2"}
});

*/

]]></xp:this.script>
        </xp:executeClientScript>
    </xp:this.script>
</xp:eventHandler>
</xp:button>

Solution

  • XSP.prompt will use the default browser prompt window. You will have limited functionality from it and, in my opinion, not a great user experience. I would recommend having your reject button open an XPages Extension Library dialog with an Edit Box to enter the comment. Bind the Edit Box to a requestScope variable - you won't need the value after the dialog closes, so you would need it at a higher scope level. In the "OK" button of the dialog run your SSJS and use the SSJS hide() method of the Dialog component to close the dialog, adding a parameter for a component on the page if you need to partially refresh it.