In Client Notes programming there is an action button:
#MailSend(Destinatari;"";"";"Subject";"";"";IncludeDoclink])&
#Command([FileSave])&#Command([FileCloseWindow])
I want to make a similar action in my xpage application which works both in XPiNC and web.
My sendto field is a DjTextarea which can have multiple values.
I tried to create a simple action for my button from xpage: Action: Send Mail. In this way, can I embedded < the IncludeDoclink from Lotus Notes> in the body of the mail? Or I need to write a javascript for this action?
Thanks for your time!
UPDATE: following #Lothar suggestions, my Save & Send button has the following code lines:
if(frmDoc.isNewNote()){
frmDoc.save();
}
var thisdoc = frmDoc.getDocument();
var tempdoc = database.createDocument();
tempdoc.replaceItemValue("Form", "Memo");
tempdoc.replaceItemValue("SendTo", thisdoc.getItemValue("txt_names"));
tempdoc.replaceItemValue("Subject", "subject");
var tempbody:NotesRichtextItem = tempdoc.createRichTextItem("Body");
tempbody.appendText("This is my Mail, click on the doc link below to open the original doc:")
tempbody.addNewLine(2);
tempbody.appendDocLink(thisdoc);
tempdoc.send();
thisdoc.recycle();
tempbody.recycle();
tempdoc.recycle();
Where frmDoc is my doc datasource. I get an error like: NotesRichTextItem.appendDocLink(lotus.domino.local.Document) null - at the appendDoclink line. - the same error I noticed in the #Fredrik useful suggestion too.
I use the HTML email function that can be found in xSnippets when sending emails in xpages.
XSnippet SSJS HTML Mime emails
or
XSnippet email Bean
None of them as an function for attaching a doclink, but you could manually add an url to the document.
Another way is to create the email manually by creating a document is the database
adding a richtextfield called body and a subject and a sendto field.
And adding a doclink to the Body field.
var doc:NotesDocument = database.createDocument();
var My_DocLink_Doc:NotesDocument=database.getDocumentByUNID("UNID_of_Document")
doc.replaceItemValue("form", "Memo");
doc.replaceItemValue("sendTo", "the_emailadress");
doc.replaceItemValue("subject", "an email to you");
var RT:NotesRichTextItem=doc.createRichTextItem("Body")
RT.appendText("This is my Text")
RT.addNewLine()
RT.appendDocLink(My_DocLink_Doc)
doc.send();
There's really not much to add to Fredrik's answer, but I'm afraid you might be looking at the wrong pieces of his solution. I just tested it myself, and it's working just fine, so here's the result, step-by-step:
my xpage is bound to a Notes form named testMail using a document datasource called mailDoc. It is built like this:
Control#1 is a textarea with a multiple separator set to a comma, so that I can enter multiple mail addresses separated by commas. The textarea is bound to a Notes field named SendTo:
<xp:inputTextarea
value="#{mailDoc.SendTo}"
id="sendTo1"
multipleSeparator=",">
</xp:inputTextarea>
Control #2 is a simple EditBox control bound to a Notes field named Subject:
<xp:inputText
value="#{mailDoc.Subject}"
id="subject1">
</xp:inputText>
A button control labelled Save & Send first saves the current document if it is New (i.e. has never been saved before), then performs all the necessary steps to send a doclink for the currently opened doc (button's onclick event); in the following code I'm using these variables:
mailDoc = my datasource object;
thisdoc = the backend doc object that the datasource is bound to;
tempdoc = a temp backend doc object used to be sent via Notes mail:
if(mailDoc.isNewNote()){
mailDoc.save();
}
var thisdoc = mailDoc.getDocument();
var tempdoc = database.createDocument();
tempdoc.replaceItemValue("Form", "Memo");
tempdoc.replaceItemValue("SendTo", thisdoc.getItemValue("SendTo"));
tempdoc.replaceItemValue("Subject", thisdoc.getItemValue("Subject"));
var tempbody:NotesRichtextItem = tempdoc.createRichTextItem("Body");
tempbody.appendText("This is my Mail, click on the doc link below to open the original doc:")
tempbody.addNewLine(2);
tempbody.appendDocLink(thisdoc);
tempdoc.send();
thisdoc.recycle();
tempbody.recycle();
tempdoc.recycle();
Result: the button code sends a mail containing a Notes document link to all the recipients that I previously entered in the SendTo field.
If I set the testMail form's property to use the Xpage in Notes (Defaults >> On Open >> Display Xpage instead >> mailSendTest), then this also works for the XPinc version. And if the recipient then clicks on the doc link the originating document of course opens in XPinc mode as well.
Remark:
I need to save the originating doc at least once otherwise the appended doc link might not be usable for the recipients; could this have been the reason why Fredrik's answer didn't work for you?
Hope this helps. If this is working for you please accept Fredrik's answer.
Update:
Changed some variable names in my code example to clarify things
I simply use these two lines:
var url =
#Left(facesContext.getExternalContext().getRequest().getRequestURL(),"newDocument.xsp")+"newDocument.xsp?documentId="+document1.getDocument().getUniversalID()+"&action=openDocument";
rtitem.appendText(url);
where newDocument.xsp is the form xsp of the document, rtitem is the rich text field of the mail. That will add the whole link to your document.
Related
I have a lotusscript function that creates new documents containing an attachment in a richtext file.
...
Dim docProcess As NotesDocument
Set docProcess = dbCurrent.createDocument
docProcess.form = "result"
...
'Attach file
Dim rtfFile As NotesRichTextItem
Set rtfFile = docProcess.Createrichtextitem("xmlFile")
Call rtfFile.Embedobject(EMBED_ATTACHMENT, "", filePath + fileName, "file")
Call docProcess.save(False, False)
My form design looks like this
$V2AttachmentOptions is computed for display, value "0"
xmlFile is a (editable) richtext field
However, when opening the document in the Notes client, it looks like this:
We are using Notes V9.01 FP8
How can I hide the attachment displayed below the line?
I found this technote, but that is not related, since I don't open the doc in edit mode (it is created on the server by an agent).
Have you tried not including the fourth parameter? The Designer manual says that it's to be used with OLE/2 objects, not for attachments. The example in the technote contradicts this, but on the other hand I have created many scripts for attachments without the fourth parameter and it's always worked as intended.
I want to be able to send the UNID of the newly created document to the user, so that the user can access the document. In the execution script;
var unid = param.documentId;
var vUnid = newDocId.getDocument().getUniversalID;
Both were picking up the parent UNID, which already existed in the browser.
This image will show you how the document looks like and will be grateful to know how to pass the newly generated UNID when document is submitted.
You need to add your code into the postSave event of your data source. The UNID for a new document only gets set when saved for the first time. Before that it's a temp value only
Write your newly generated UniversalID into a sessionScope variable
sessionScope.newUnid = newDocId.getDocument().getUniversalID;
and use it in next XPage called after submit
var useTheNewUnid = sessionScope.newUnid;
how to send error message to user from agent when using xpages?
Here the detail engine:
1. The xpages contains a button. when the button was clicked then it will call the agent to process the context info
2. On processing the agent, is it possible to send warning message to user (dialog box)? If yes, What command for send it?
Thanks
An agent cannot directly interact with XPages. One method would be to write output to a control document and for XPages to pick up that control document and put the message in a requestScope variable to be displayed on the page.
I agree with Paul. Just adding a small snippet here for you to start:
var agentName:String = "agentName";
var agent:NotesAgent = database.getAgent(agentName);
if (agent != null)
{
var doc:NotesDocument = document1.getDocument() // assuming datasource name is document1
agent.runWithDocumentContext(doc);
/*
In your agent you process a document with particular form and say a unique id of the passed
document context
*/
var v:NotesView = database.getView("warningView"); // For eg. stored in a warning view
var warningDocument:NotesDocument = v.getDocumentByKey(doc.getUniversalID());
// You can process the document according to your needs then ( you can do later step after your dialog is opened)
}
else
{
// throw and error message
}
Hope this helps.
Chintan and Paul are correct. Using the technique described in this article you can capture all print output from an agent and use that in the XPage. However....
This is an excellent opportunity to pay down some technical debt and transform your agent into a bean. If it is well written, it should be easy. If its not, then you clean it up
I've start to develop XPage 7 weeks ago, and i have a problem with "getting data".
On my first page i have a view with a lot of documents, and a button who redirect me on a new page, to create a new document. On my first page i can select a document and when i click on the button i put my id document selected on a sessionSCope.
Button script:
var viewPanel=getComponent("viewPanel1");
var docIDArray=viewPanel.getSelectedIds();
var docUID=database.getDocumentByID(docIDArray[0]).getUniversalID();
sessionScope.put("docUID", docUID);
context.redirectToPage("AjoutSuivi");
On my new XPage i want to get some data on my selected document so on clientLoad of the XPage i execute this script:
var docUID = sessionScope.get("docUID");
var doc:NotesDocument = database.getDocumentByUNID(docUID);
getComponent("contactname1").setValue(doc.getItemValueString("ContactName"));
On my database i have a field "ContactName" and on my XPage i have a field contactname1. I have try with "database.getDocumentByID(docUID)" and i'm sure that "database" is the good link of the database.
When i try it, there is nothing on the field contactname1 have u an idea why that's doesn't work ?
So much thank's if you can help me
Yann
PS: sorry for my bad english
Put your code into the event afterPageLoad and it should work (for the execution order of events take a look at XPage Cheat Sheet #1 - The Page Lifecycle).
Y4nn welcome to the XPages club. When you bind a control to a data source it is better to set the value in the data source than in the control. So you write:
document1.getDocument().replaceItemvalue(...)
(picking on a glass now, watch out for correct syntax)
When a form is saved via a button, I want to also create a new document using the form "MSG", which has fields for message title, body and recipient. At first I thought it might be possible using only a JS library, but now I am unsure. What about opening an unrendered XPage which is bound to that document's form, and inheriting the values into it?
I hope I understand your question right: try inserting code like this in XPage's datasource (e.g. document1) postSave event:
var doc:NotesDocument=database.createDocument();
doc.replaceItemValue("Form","msg");
doc.replaceItemValue("title",document1.getItemValueString("title"));
...
doc.save(true);