Doclink not opening in xpages - xpages

i am using this code it is show doclink but it is not opening it show some error.
var document1:NotesDocument = database.createDocument();
var rtitem:NotesRichTextItem = document1.createRichTextItem("body");
document1.replaceItemValue("Form", "memo");
document1.replaceItemValue("SendTo", "lotusadm#san.org");
document1.replaceItemValue("Subject", "Rajesh");
rtitem.appendText("Some text here... ");
rtitem.addNewLine(2);
rtitem.appendText("NotesDocument.NotesURL");
rtitem.appendDocLink(document1, "Some comment text");
rtitem.addNewLine(2);
document1.save();
document1.send();
Error:-
Please tell me how to open a doclink.

I guess you want to create a link to XPage's current document in your email.
You might have a data source defined in your XPage which is named "document1" as default
<xp:this.data>
<xp:dominoDocument
var="document1"
action="editDocument"
...
</xp:dominoDocument>
</xp:this.data>
Then, your code would look like this:
var documentMail:NotesDocument = database.createDocument();
var rtitem:NotesRichTextItem = documentMail.createRichTextItem("body");
documentMail.replaceItemValue("Form", "memo");
documentMail.replaceItemValue("SendTo", "lotusadm#san.org");
documentMail.replaceItemValue("Subject", "Rajesh");
rtitem.appendText("Some text here... ");
rtitem.addNewLine(2);
rtitem.appendText("NotesDocument.NotesURL");
rtitem.appendDocLink(document1.getDocument(), "Some comment text");
rtitem.addNewLine(2);
documentMail.save();
documentMail.send();
I changed email document's object name to documentMail and added .getDocument().
document1.getDocument() gives the data sources' document.

Related

Values from Edit Box controls not saved on Notes Document via SSJS

On an custom control I have data-source bounded to a panel control:
<xp:panel>
<xp:this.data>
<xp:dominoDocument var="attachDoc" formName="fAttachment"></xp:dominoDocument>
</xp:this.data>
...
</xp:panel>
Within the panel I have some Edit Box controls e.g.
<xp:inputText id="inpOfficial" value="#{attachDoc.migration}">
When I try to save the doc via SSJS the edit boxes are not saved:
function saveAttachment(){
try {
var doc:NotesDocument = attachDoc.getDocument();
doc.save();
}
}
What am I missing?
The custom control is repeated over the xpage. The custom control has it's own save button calling the saveAttachment() function
Your saveAttachment() function appears to be trying to save a back end notes document on the database. To pass through the changes in the UI you need to run attachDoc.save() which passes the NotesXSPDocument (UI doc) through to the back end NotesDocument saved to the database.
(Assuming your try statement has a catch but you've left that out)
https://www.ibm.com/support/knowledgecenter/en/SSVRGU_9.0.1/reference/r_wpdr_xsp_xspdocument_r.html
Andrew Norrie is right.
If you still wish to use the back-end NotesDocument, get it like this:
var doc:NotesDocument = attachDoc.getDocument(true);
The parameterized getDocument method will update the back-end NotesDocument with the model values before return.

Include doc link and graphics in email form Xpages

I want to send emails from an Xpage application. Want to include some type of header graphic or HTML styling, and it must include a doc link.
I started using Ulrich Krause's modification of Tony McGuckin's excellent SSJS here
However, I have two issues that I cannot resolve - adding the doc link an and also a graphic.
var doc:NotesDocument = currentDocument.getDocument();
var tmp:String ="A New Location Has Been Created: " + document1.getDocument().getItemValueString("businessUnitName") + ".\n\n" + "Please click this doc link and add any additional approvers ==> ";
emailBean.setSendTo("name#domain.com");
emailBean.setSubject("Lcoations");
emailBean.setSenderEmail("name#domain.com");
emailBean.setSenderName("Locations");
emailBean.setFieldName("Body");
//emailBean.setDocument(document1);
emailBean.addHTML("<table><tr><th>Month</th><th>Savings</th></tr><tr><td>January</td><td>$100</td></tr></table>")
emailBean.addHTML(tmp);
emailBean.setBannerHTML("<table><tr><th>Month</th><th>Savings</th></tr><tr><td>January</td><td>$100</td></tr></table>");
emailBean.setFooterHTML("<p>Kind regards,<br/>Samantha<br/>0012 3456 789</p>");
emailBean.send();
I have commented out the setDocument code as it doesn't work and isn't necessary.
I have an image resource in the db called locations.pgn that I want to include - or I can put it on the web at a url I control.
How do I pass in a doc link? I have computed it, but I just don't now how to add it.
The other method I have tried is a more roll my own.
I have this in a button on the Xpage form:
var doc:NotesDocument = currentDocument.getDocument();
var nteUrl:String = doc.getNotesURL();
var sndTo:String ="name.domain.com";
var sndFrm:String ="ame.domain.com";
var sbj:String ="A New Location Has Been Created: blah blah blah");
var body:String =""A New Location Has Been Created: blah blah blah");
sendEmail(sndTo,sndFrm,sbj,body,doc);
And then my function:
function sendEmail(sndTo,sndFrm,subject,body,trgDoc) {
var doc:NotesDocument = database.createDocument();
doc.replaceItemValue("Form","Memo");
doc.replaceItemValue("Subject",subject);
doc.replaceItemValue("Principal",sndFrm);
doc.replaceItemValue("From",sndFrm);
doc.replaceItemValue("SendTo",sndTo);
doc.replaceItemValue("DisplaySent",sndTo);
doc.replaceItemValue("SMTPOriginator",sndTo);
var memo:NotesRichTextItem = doc.createRichTextItem("Body")
var urlgif="/locations.png";
memo.embedObject(NotesEmbeddedObject.EMBED_OBJECT, "",urlgif,null);
memo.appendText(body);
memo.appendDocLink(trgDoc);
doc.send();
return ;
}
This attaches the file as an attachment, not as a picture. Can't find a method to do that.
I am agnostic about which method I use, I just want to get one nailed down and tightened up so I can use it throughout my applications.
Any help would be greatly appreciated.
You create the email based on HTML with emailBean.addHTML(... your html ...).
Use the syntax
link text
to add links and
<img src="url" ...>
to add images.
Instead of an URL you can code the picture in base64 and include it completely in your html like this
<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABkAAAAZ
AQAAAADskrjOAAAAfElEQVR42mNgrDrAwFCbHs/A4Gp8EUgIBAKJSUCiVuY+A
wNjqAMDw//T/xsYDK9nMDB4/zAGSkimMTAIbz/DwHDitRwDg1agNQPD0YTyBoZ
L/ncbGHg3swN1WBcD9f4Lb2CoLS8AmufB3sDgehWo2LXRDSjmtRkoG5TCAACQ
1SM9QzyOtAAAAABJRU5ErkJggg==">

XPages: image onCclick needs 2 clicks to do what is expected

I have a custom control that contains 2 images: add and remove from favorites.
There is some code on the onCLick event of the image, and both images use a SSJS function to see if the current document is already in the favorites or not, in the visible property of each image.
All works well, execpt that I need to click twice on the image in order to see the changes in the UI. Both onClick events are set to FullUpdate (also tried partial update with the panel that contains the images).
I could move all the favorites logic into session scope variables, but I think this should work as is. I just don't understand why I need to click twice, as if the partial refresh doesn't do anything (though it is, as I see the reload Arrow in the browser!).
Can it be that the code takes too long to execute and the refresh doesn'T get the updated info???
Here's the custom control code:
<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core" xmlns:xe="http://www.ibm.com/xsp/coreex">
<xp:this.resources>
<xp:script src="/AppUtils.jss" clientSide="false"></xp:script>
</xp:this.resources>
<xp:image url="/favorites-add.png" id="image1"
alt="Add to Favorites" title="Add to Favorites">
<xp:this.rendered><![CDATA[#{javascript:!isInFavorites(document1.getDocument().getUniversalID(), userBean.canonicalName);
}]]></xp:this.rendered>
<xp:eventHandler event="onclick" submit="true" refreshMode="complete">
<xp:this.action><![CDATA[#{javascript:addToFavorites(document1.getDocument().getUniversalID(),userBean.canonicalName);}]]></xp:this.action>
</xp:eventHandler>
</xp:image>
<xp:image url="/favorites-remove.png" id="image2"
alt="Remove from Favorites" title="Remove from Favorites">
<xp:this.rendered><![CDATA[#{javascript:isInFavorites(document1.getDocument().getUniversalID(),userBean.canonicalName);
}]]></xp:this.rendered>
<xp:eventHandler event="onclick" submit="true"
refreshMode="complete">
<xp:this.action><![CDATA[#{javascript:removeFromFavorites(document1.getDocument().getUniversalID(),userBean.canonicalName);}]]></xp:this.action>
</xp:eventHandler>
</xp:image>
</xp:view>
And here's the SSJS:
function addToFavorites(unid, userName) {
var newDoc:NotesDocument = database.createDocument();
newDoc.appendItemValue("Form","Favorite");
newDoc.appendItemValue("UserName", userName);
newDoc.appendItemValue("DocUNID", unid);
newDoc.save();
return;
}
function removeFromFavorites(unid, userName) {
var notesView:NotesView = database.getView("(lkpFavorites)");
var keys = new java.util.Vector();
keys.addElement(userName);
keys.addElement(unid);
var coll:NotesDocumentCollection = notesView.getAllDocumentsByKey(keys, true);
if(coll.getCount()==1) {
coll.getFirstDocument().remove(true);
}
return;
}
function isInFavorites(unid, userName) {
var notesView:NotesView = database.getView("(lkpFavorites)");
var keys = new java.util.Vector();
keys.addElement(userName);
keys.addElement(unid);
var coll:NotesDocumentCollection = notesView.getAllDocumentsByKey(keys, true);
if(coll.getCount()>0) {
return true;
} else {
return false;
}
}
I'd suggest you to put an xp:link around your image to cast the event code instead of using the evennts of the image directly.
OK, not sure what happened there but I manually edited the custom control's source to see wheter I had empty eventHandler as suggested by Oliver, and it started to work as expected. I am totally unsure of what I changed: to my knowledge, all I did was to add extra "returns" in the source view, to make it more readable... Christmas gift I guess.
All is good now. Thanks to all :)

xpages get UNID for a document/datasource

I'm using Mark Hughes picklist on my xpage which is using a datasource. The view from which I pick the values is listing documents having another datasource.
I put the selected value into an <xp:inputText>. I do want to create a link which should redirect me to the listed document from the view ( from it I took the value ). In other words, I do want to find out the UNID of the document from the view, which I did selected it.
I tried the following code for the ssjsSelectFunction:
var unid = viewScope.unid;
if(typeof unid != "undefined" && unid != null)
{
var doc = database.getDocumentByUNID(unid);
var val1 = doc.getItemValueString("txt_numeAcord_1");
var val2 = doc.getUniversalID();
getComponent("inputText24").setValue(val1);
getComponent("inputText25").setValue(val2);
}
But after selecting the desired doc. from the picklist, only inputText25 is updated with the value ( UNID ), the inputText24 is empty. Only if I open again the picklist and select the doc., the inputText24 field value is added. I guess I'm missing something.
How can I achieve this?
My xpage code:
<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core"
xmlns:xc="http://www.ibm.com/xsp/custom"
xmlns:xe="http://www.ibm.com/xsp/coreex" >
<xp:this.data>
<xp:dominoDocument var="Contr" formName="(fmFormularCIP)"></xp:dominoDocument>
<xp:dominoView var="view1" viewName="vwAcord"></xp:dominoView>
</xp:this.data>
<xp:panel id="AcordCadru">
   
<xp:br></xp:br>
  
<xp:checkBox text="Acord cadru" id="checkBox6"checkedValue="Da" uncheckedValue="Nu" value="#{Contr.chkAcord}">
<xp:eventHandler event="onchange" submit="true"
refreshMode="partial" refreshId="AcordCadru">
</xp:eventHandler>
</xp:checkBox>
 
<xp:inputText id="inputText24" value="#{Contr.acord}">
</xp:inputText>
<xc:viewpicklist rowsPerPage="10"
buttonImage="./folder_explore.png" tableClass="tablecellgreen"
headerClass="headerclass" rowClass="odd, even" searchBar="false"
searchButtonText="Search" searchButtonClass="button2"
searchBarClass="headerclass" pagerStyleFirst="navbutton1"
pagerStylePrevious="navbutton2" pagerStyleCurrent="navbutton4"
pagerStyleNext="navbutton2" pagerStyleLast="navbutton3"
typeAheadBar="false" select="UNID" onReturn="Set Scope Value"
bottomBarClass="bottomround headerclass" cancelButtonText="Cancel"
cancelButtonClass="button2 floatthisright" type="Single Value"
finishButtonText="Finish" finishButtonClass="button2 floatthisright"
multiSelectButtonAddImg="./add.png"
multiSelectButtonRemoveImg="./delete.png"
picklistButtonClass="button" openDialogWith="Button"
picklistLinkImg="./add.png" multiSelectLinkAddImg="./add.png"
multiSelectLinkRemoveImg="./delete.png" selectWith="Button"
multiValueSeparator="," clearSearchImg="./cross.png"
SelectCellWidth="30px" dialogID="dialog1"
dialogTitle="Alegeti nr. acord cadru" fieldName="inputText24"
refreshID="AcordCadru" datasrc="view1" selectColumn="0"
varName="viewScope.unid">
<xc:this.viewColumn>
<xp:value>0</xp:value>
<xp:value>1</xp:value>
<xp:value>2</xp:value>
<xp:value>3</xp:value>
<xp:value>4</xp:value>
</xc:this.viewColumn>
<xc:this.ssjsSelectFunction><![CDATA[#{javascript:
var unid = viewScope.unid;
if(typeof unid != "undefined" && unid != null)
{
var doc = database.getDocumentByUNID(unid);
var val1 = doc.getItemValueString("txt_numeAcord_1");
var val2 = doc.getUniversalID();
Contr.setValue("acord",val1);
Contr.setValue("sv",val2);
}}]]></xc:this.ssjsSelectFunction>
</xc:viewpicklist>
<xp:br></xp:br>
   
<xp:inputText id="inputText25" value="#{Contr.sv}">
</xp:inputText>
</xp:panel>
</xp:view>
inputText24 doesn't get the selected value because the execution of ssjsSelectFunction's code is too late. It gets executed during the refresh of panel "AcordCadru" caused by parameter refreshID. All fields positioned in front of xc:viewpicklist get refreshed before ssjsSelectFunction's code execution. That's why inputText24 doesn't get the new selected value but inputText25 which comes after xc:viewpicklist does.
If you put inputText24 behind xc:viewpicklist then it will get the new selected value.
But, probably you want to have field inputText24 first and the picklist button xc:viewpicklist after. For this
delete the ssjsSelectFunction code
add a computed field in front of inputText24 with pretty the same code
<xp:text
escape="true"
id="computedField1">
<xp:this.value><![CDATA[#{javascript:
var unid = viewScope.unid;
if (unid && unid !== Contr.sv) {
var doc = database.getDocumentByUNID(unid);
var val1 = doc.getItemValueString("txt_numeAcord_1");
Contr.setValue("acord",val1);
Contr.setValue("sv",unid);
}
return "";
}]]></xp:this.value>
</xp:text>
It will set the new selected values to document and made them visible in inputText24 and inputText25 right away.

Post status update to IBM Connections using extlib

I am trying to post an update i.e. a status message to IBM Connections using the extlib.
I have used the extlib with connectionsLTPA endpoint which works really well for getting the communities list. However I wish to add functionality to update the users status.
So far I have tried using
<xp:this.data>
<xe:connectionsData var="connectionsData1"
endpoint="connections" serviceUrl="/profiles/atom/mv/theboard/entry/status.do?email=#{userBean.email}">
</xe:connectionsData>
</xp:this.data>
and then in the event handler
var sb = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>" +
"<author><name>#{userBean.displayName}</name></author>" +
"<entry xmlns=\"http://www.w3.org/2005/Atom\">" +
"<content type=\"html\">" +input + "</content>" +
"<category scheme=\"http://www.ibm.com/xmlns/prod/sn/type\" term=\"status\" />"+
"</entry>\r\n";
var output = #{connectionsData1}.post(null, sb, "xml");
however this throws an error trying to call post on the binded data point.
Anybody able to point me in the right direction?
Thanks
I have found that implementing the sbt by doing the follwing:
<xp:button id="button2">
<xp:this.value>Update my status</xp:this.value>
<xp:eventHandler event="onclick" submit="true"
refreshMode="partial">
<xp:this.action><![CDATA[#{javascript:try {
var svc = new sbt.ConnectionsService("/profiles/atom/mv/theboard/entry/status.do?email=" +userBean.email);
var sb = new java.lang.StringBuilder();
sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
sb.append("<entry xmlns=\"http://www.w3.org/2005/Atom\">");
sb.append("<category scheme=\"http://www.ibm.com/xmlns/prod/sn/type\" term=\"entry\"/>");
sb.append("<category scheme=\"http://www.ibm.com/xmlns/prod/sn/message-type\" term=\"status\"></category>");
sb.append("<content type=\"text\">");
sb.append(getComponent("inputText1").getValue());
sb.append("</content>");
sb.append("</entry>");
var msg = svc.put(null, sb.toString(),"xml");
var msg = "updated users profile status";
#WarningMessage(msg)
} catch(e) {}
}]]></xp:this.action>
</xp:eventHandler>
</xp:button>
The reason it wasn't working correctly is that the atom feed needed to be declared as an entry. This article in the connections doc for 2.5 http://publib.boulder.ibm.com/infocenter/ltscnnct/v2r0/index.jsp?topic=/com.ibm.connections.25.help/r_api_prof_update_photo.html explains the required parts of the xml atom document.

Resources