MS Word using POI4XPAGES - xpages

I am facing problem using the POI4Xpages with MSword 2016 version
Here is my setup details
- I have lotus notes client 9.0 FP1
- Installed POI4XPages server and designer client
- POI Xpages (1.3.1)
- I used MSWord2016
I'm able to get it setup running. My problem is that ,the first field (<>) inside the word document gets only get populated with values from the xpage document. There rest of fields inside the word document don't get the values populated.
For now I am trying to populate the first 3 fields into the word document.
I am attaching here my button code and WORD poi custom control
Thank you in advance.
***********This is my generate button***********
<xp:eventHandler event="onclick" submit="true"
refreshMode="complete">
<xp:this.action>
<xp:actionGroup>
<xp:executeScript>
<xp:this.script><![CDATA[#{javascript:try{
var doc = document1.getDocument(true);
viewScope.put("tmpf1",doc.getItemValueString("kindofCase"));
viewScope.put("tmpf2",doc.getItemValueString("TypeofCase"));
viewScope.put("tmpf3",doc.getItemValueString("cxExt15"));
viewScope.put("tmpf4",doc.getItemValueString("cxAmount"));
viewScope.put("tmpf5",doc.getItemValueString("cxClientName"));
viewScope.put("tmpf6",doc.getItemValueString("caseNum"));
viewScope.put("tmpf7",doc.getItemValueString("BenfAcct"));
viewScope.put("tmpf8",doc.getItemValueString("BenfBranch"));
viewScope.put("tmpf9",doc.getItemValueString("cxDLQ"));
viewScope.put("tmpf10",doc.getItemValueString("cxForm1"));
viewScope.put("tmpf11",doc.getItemValueString("cxForm2"));
viewScope.put("tmpf12",doc.getItemValueString("cxRecRequestvia"));
viewScope.put("tmpf13",doc.getItemValueString("cxChannel"));
viewScope.put("tmpf14",doc.getItemValueString("BenfBank"));
viewScope.put("tmpf15",doc.getItemValueString("BenfName"));
viewScope.put("tmpf16",doc.getItemValueString("BenfID"));
viewScope.put("tmpf17",doc.getItemValueString("cxLength4"));
viewScope.put("tmpf18",doc.getItemValueString("BenfNationality"));
viewScope.put("tmpf19",doc.getItemValueString("BenfState"));
viewScope.put("tmpf20",doc.getItemValueString("BenfCity"));
//print (viewScope.tmpf2);
} catch (e){
print (e);
}}]]></xp:this.script>
</xp:executeScript>
<wgpoi:generateDocument documentId="wb"></wgpoi:generateDocument>
</xp:actionGroup>
</xp:this.action>
</xp:eventHandler>
</xp:button>
**************POI word custom control **************
<wgpoi:document id="wb" downloadFileName="whistleblower.docx"
pathInfo="download">
<wgpoi:this.templateSource>
<wgpoi:resourcetemplate fileName="word2016.docx"></wgpoi:resourcetemplate>
</wgpoi:this.templateSource>
<wgpoi:this.bookmarks>
<wgpoi:docbookmark value="#{javascript:viewScope.tmpf1}"
name="field1">
</wgpoi:docbookmark>
<wgpoi:docbookmark value="#{javascript:viewScope.tmpf2}"
name="field2">
</wgpoi:docbookmark>
<wgpoi:docbookmark value="#{javascript:viewScope.tmpf3}"
name="field3">
</wgpoi:docbookmark>
</wgpoi:this.bookmarks>
</wgpoi:document>

Related

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>
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.
Don't bind that field to your document (in read mode). Bind it to viewScope or requestScope variable.
Also, look here for inspiration.
To accomplish this in the past, I have used CSS to hide the input fields and buttons. The client-side script is defined separately from the button actions.
<xp:text escape="false"><xp:this.value><![CDATA[
<script>
function promptBox(){
// ... do whatever to get the data input into
// XSP.getElementById("#{id:inputText1}").value
// OR if using JQuery $('.tester).val()
// then click hidden Save button
$('.reject').click()
// OR
XSP.getElementById("#{id:button1}").click()
}
</script>
]]></xp:this.value></xp:text>
<!-- hide the input field with CSS -->
<xp:inputText
id="inputText1"
value="#{viewScope.tester}"
defaultValue="#{viewScope.tester}"
styleClass="tester hidden">
</xp:inputText>
<!-- hide the button with CSS -->
<xp:button
value="Reject"
styleClass="reject hidden"
id="button1">
<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; /* scoped variable already set */
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:button>
<!-- use link for button - style it with CSS -->
Reject
I do not like having both client-side and server-side scripts bound to the same button, the execution order of the code is not easily managed. There are other ways to combine these client side fields and server side scripts, but this is a simple demonstration.

XPages appendDocLink on Anonymous User Error

I am attempting to replace my 'traditional Notes' User Name and Password Request form with one designed in XPages, mainly because the #SendMail Formula no longer works with Firefox or Chrome.
Anonymous users are to complete an XPage Form, hit a submit button which then sends an email to our support team, which is to include a Doc Link back to an internal Notes form of the same document, - I don't want to change this internal form as there is lots of lotusscript programming associated with it for processing.
I have the XPage marked as Available to Public Access as is the form associated with it. I also have ComputeWithForm set to both.
I can access the data document components e.g. append to the mail rtf body using doc.getItemValueString("field"), but I cannot do the same with appendDocLink it appears to fail due to access problems. If I set Anonymous to Manager access in the ACL the Doc link is appended.
<xp:button value="Submit" id="button1" style="margin-top:50.0px">
<xp:eventHandler event="onclick" submit="true" refreshMode="complete" immediate="false" save="false" id="eventHandler1">
<xp:this.action>
<xp:actionGroup>
<xp:saveDocument var="document1"></xp:saveDocument>
<xp:executeScript>
<xp:this.script><![CDATA[#{javascript: if(document1.isNewNote()){document1.save();}
var doc:NotesDocument = document1.getDocument(true);
var receiverEmail = "Support Requests";
var requestor = "xyz#company.co.uk";
db = sessionAsSignerWithFullAccess.getCurrentDatabase();
var memo = db.createDocument()
memo.appendItemValue("Form","Memo");
memo.appendItemValue("Principal","Company#NotesDomain");
memo.appendItemValue("From",requestor);
memo.appendItemValue("INetFrom",requestor);
memo.appendItemValue("DisplaySent",requestor);
memo.appendItemValue("SMTPOriginator",requestor);
memo.appendItemValue("Subject","NEW: Name & Password Request for "+getComponent("reqCompany1").getValue());
var rtitem:NotesRichTextItem = memo.createRichTextItem("Body");
rtitem.addNewLine();
rtitem.appendText("A new Name & Password Request has been logged by "+getComponent("reqFirstName1").getValue()+" " + getComponent("reqSecondName1").getValue()+" of "+ getComponent("reqCompany1").getValue());
rtitem.addNewLine();
rtitem.appendText("Click the Doc link to action it. ");
rtitem.appendDocLink(doc);
memo.send(receiverEmail);}]]></xp:this.script>
</xp:executeScript>
<xp:openPage name="/UserNandPSubmitted.xsp"></xp:openPage>
</xp:actionGroup>
</xp:this.action>
</xp:eventHandler>
</xp:button>
The following errors occur.
com.ibm.jscript.InterpretException: Script interpreter error, line=25, col=8: [TypeError] Exception occurred calling method NotesRichTextItem.appendDocLink(lotus.domino.local.Document)
null
NotesException: Notes error: You are not authorized to perform that operation
lotus.domino.local.RichTextItem.appendDocLink(Unknown Source)
lotus.domino.local.RichTextItem.appendDocLink(Unknown Source)
Any help would be greatly appreciated.
Make sure Anonymous user can access the default view of the database - so make it accessible to public access users. appendDocLink() method requires this view in order to append doc link to RT item.

xpages save / cancel actions scenario

I will describe shortly my little project application:
the main doc. content is Cdoc ( datasource which contains fields + a button ). This button displays a dialog which is Pdoc ( a datasource ) - before showing the button I will save the doc. to get the UNID and then I will pass it to the Pdoc, I want to link the Cdoc and Pdoc with the UNID.
My button which shows the dialog:
<xp:button value="Adding Pdoc from the dialog" id="button3"
styleClass="lotusFormButton" refreshMode="partial">
<xp:eventHandler event="onclick" submit="true"
refreshMode="partial" refreshId="computedField3">
<xp:this.action><![CDATA[#{javascript: if ( Cdoc.isNewNote() ) { Cdoc.save(); }
Cdoc.setValue("computedField3",Cdoc.getDocument().getUniversalID());
getComponent('exampleDialog').show()}]]></xp:this.action>
</xp:eventHandler>
The dialog / Pdoc contains just 1 button: Save ( because the X button is implicitly added to the dialog )
<xp:button value="Salvare" id="button6" styleClass="lotusFormButton">
<xp:eventHandler event="onclick"
submit="true" refreshMode="partial" immediate="false"
save="false" refreshId="viewPanel1">
<xp:this.action><![CDATA[#{javascript:Pdoc.save();
getComponent('exampleDialog').hide();
}]]>
</xp:this.action>
</xp:eventHandler>
So, it saves the docs. from Pdoc and they are displayed in an embedded view from Cdoc.
The main. doc Cdoc contains also 2 (actions) buttons:
Cancel: redirect to Previous Page.
and
Save
<xp:button value="Salvare" id="buttonSave" styleClass="lotusFormButton" rendered="#{javascript:currentDocument.isEditable()}">
<xp:eventHandler event="onclick" submit="true"
refreshMode="partial" immediate="false" save="true"
id="eventHandler1">
<xp:this.action><![CDATA[#{javascript:if (Cdoc.getItemValueString("txt_UNID")!= "") {
Cdoc.save();
}
facesContext.getExternalContext().redirect("http://ourserver.ro/XApp.nsf/view.xsp")
}]]></xp:this.action>
</xp:eventHandler>
</xp:button>
The problem is:
Let say I'll create 3 docs. from Pdoc from the dialog, the Cdoc. is already saved ( because the UNID was obtained ). If I save then using Cdoc Save, my main view panel from view.xsp will display:
one doc. Cdoc with its 3 Pdoc docs. ( I need just this case to be displayed )
another Cdoc ( I guess when I first obtain the UNID and I saved the Cdoc to obtain the UNID, this is the Cdoc in this case. Btw, if I save again Cdoc using the Save button , will the UNID will change ? ) and one empty ( don't know why ) Pdoc from the dialog.
How should my Save button from Cdoc should be like? Should I change also the Save from Pdoc button?
Thanks for your time.
I believe save="true" on a button will submit and save all datasources on the page. That could explain spurious Pdoc documents. You're calling the save in script, so you don't need save="true" - you can just use a normal Button type rather than Submit type for the button.
Once a Document has been saved, the UNID will not be changed.

Jump to another page in a Single Page Application

I am writing a system for our forklift drivers in XPages. Basically our machines in production are going to get a iPod with a single big button on it. When they press the button I add a document to the Notes database (see code below). The forklife drivers have an iPad with a view that displays all the calls - they then select one call and drive to that machine. Once the machine operator has pressed the call button they can see some computed text saying that a forklift is command and another Cancel button.
I have it working (well, sort of) - but cannot seem to get the page in the "Single Page Application" to refresh.
This is the code that I have on a button - how do I now get the page to refresh - or how do I move to another page (in the "Single Page Application" using JavaScript) - sorry, I am just stumped!
Thanx for any help
Ursus
// setup date and time
var dt:NotesDateTime = session.createDateTime("Today 12");
dt.setNow();
// create a new document
var newDoc = database.createDocument();
// now set your fields
newDoc.replaceItemValue ("form", "fmRuf");
newDoc.replaceItemValue ("maschineName", sessionScope.displayName);
newDoc.replaceItemValue ("maschineNotesName", sessionScope.notesName);
newDoc.replaceItemValue ("maschineUm", dt);
newDoc.appendItemValue ("status", "20");
newDoc.computeWithForm(true, false);
// save the document
newDoc.save();
If you select the refresh mode to complete, the whole site should refreshed.
<xp:button value="label" id="button4">
<xp:eventHandler event="onclick" submit="true" refreshMode="complete">
<xp:this.action><![CDATA[#{javascript://SOME CODE}]]></xp:this.action>
</xp:eventHandler>
</xp:button>
Or try this code
<xp:button value="Beschriftung" id="button4">
<xp:eventHandler event="onclick" submit="true" refreshMode="complete" immediate="false" save="true">
<xp:this.action>
<xp:actionGroup>
<xp:actionGroup condition="#{javascript://someCode}"></xp:actionGroup>
<xp:openPage name="/YourXpages.xsp"></xp:openPage>
</xp:actionGroup>
</xp:this.action>
</xp:eventHandler>
</xp:button>

QueryDocumentDelete in Xpages

The QueryDocumentDelete in Database script only seems to run from the Notes UI client when a document is deleted. Is there a similar event when a document is deleted with the Delete Selected Documents simple action?
You're right, QueryDocumentDelete in database script is a Notes UI function and runs only from the Notes client.
Unfortunately, there is no similar event in simple action Delete Selected Documents.
An easy workaround is to write the whole functionality of "Delete Selected Documents" on your own. This way you can do things you want to before documents get actually deleted or prevent certain documents from deletion.
Here is a sample code for a button "Delete Selected Documents" which deletes documents in a view panel (with id "viewPanel1"):
<xp:button
value="Delete Selected Documents"
id="button1">
<xp:eventHandler
event="onclick"
submit="true"
refreshMode="complete">
<xp:this.script><![CDATA[
if(!XSP.isViewPanelRowSelected("#{id:viewPanel1}", "_colcbox")){
XSP.alert("Please select one or more documents to delete.");
return false;
}
if (!XSP.confirm('Are you sure you want to delete selected documents?')){
return false;
}]]></xp:this.script>
<xp:this.action><![CDATA[#{javascript:
var viewPanel = getComponent("viewPanel1");
var selectedIds = viewPanel.getSelectedIds();
for(i=0; i < selectedIds.length; i++) {
var docId = selectedIds[i];
var doc = database.getDocumentByID(docId);
// do things here you would do on QueryDocumentDelete
doc.remove(true);
doc.recycle();
}}]]></xp:this.action>
</xp:eventHandler>
</xp:button>

Resources