XPages appendDocLink on Anonymous User Error - xpages

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.

Related

MS Word using POI4XPAGES

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>

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.

Exception thrown when deleting document in XPages via doc.remove() method

I added a Delete link in an xp:repeat to delete the document for the row, with "rowVar" the variable for the repeat to access thye document entries.
Here is the code for the Delete link in the repeat:
<xp:link escape="true" id="link2"
style="width:50.0px;display:inline-block" text="Delete">
<xp:eventHandler event="onclick" submit="true"
refreshMode="partial" refreshId="panelChemLog" immediate="true">
<xp:this.action><![CDATA[#{javascript:
var deleteUNID = rowVar.getUniversalID();
println(deleteUNID);
var doc:NotesDocument = database.getDocumentByUNID(deleteUNID);
println(doc.getCreated() );
doc.remove(true);
}]]></xp:this.action>
</xp:eventHandler>
</xp:link>
I included the println statements and I can see in my log that the deleteUNID and doc object is set, but the code throws this exception on the final doc.remove(true) statement:
Script interpreter error, line=5, col=5: [TypeError] Exception occurred calling method NotesDocument.remove(boolean) null
How do I code the Delete link to delete the document for the row in the repeat?
I've seen this error before several times. Just tested to be sure. If the user does not have deletion privilege, it will throw such a meaningless error.
If you look at the Java stack trace, you can confirm by the following at the bottom of the trace.
NotesException: Notes error: You are not authorized to perform that
operation
You might use database.queryAccessPrivileges(...) method to be sure within the code.

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