How to link to an xpage in email? - xpages

In lotusscript I usually do the following to create a simple email which contains a link that points to a notes database/view. Is there any way I can modify the link(appenddoclink) so that it opens an xpage? Say my xpage name is "Staff_Page".
Dim maildoc As NotesDocument, rtitem As NotesRichTextItem
Set maildoc=New NotesDocument(db)
maildoc.subject="Email Address(s) For Your Approval"
Set rtitem=New NotesRichTextItem(maildoc, "Body")
Call rtitem.Appendtext("Dear John,")
Call rtitem.Addnewline(2)
Call rtitem.Appenddoclink(db, "", "Click to open the XPage.")
Call maildoc.Send(False, "john#mail.com")
I've looked at the XPages URL Cheat Sheet but those are not lotusscript. I'm doing XPiNC with some lotusscript agent.

Easiest one is to specify in your Form properties "open xpage instead"
Second option is to specify a URL link pointing to it with the href=notes://server/....
You might be better off using mime mail (snippets for that on OpenNTF) since you have easier formatting options

Related

Why is the wrong form opening when I click the doc link I created from a SSJS function?

Ok, this is weird. I created an xpage input form. After the form is filled out, a document is created. I then create an email to notify people that the document has been created. I drop a doclink to the newly created document in the body of the email. During testing, I noticed that when I click the link in the email, the wrong Notes Form is opened. Instead of the 'TrainingRequest' form displaying the fields, the form 'Feedback' opens up instead. Here's what I checked:
- On the xpage data section, the 'form' is set to 'TrainingRequest'.
- When I open the document via the doc link, the field 'form' has the value 'TrainingRequest', which is correct. Yet it's displaying the 'Feedback' form.
- When I check the other field properties of the document, all the correct fields from the 'TrainingRequest' form are there and populated correctly.
- When I open the document via the view, the correct Notes form 'TrainingRequest' opens.
- There is no default form in the database design.
Has anyone seen this before?
thanks
clem
Doc links are always created using the default view of your application. If there is a form formula in this view then this overrides the form in the document. Remove the form formula of the default view and it works.
I almost NEVER use form formulas in my application because of the side effects.
Source code would be useful. But initial best guess based on what you're saying is you have two datasources on the XPage, neither have ignoreRequestParams set, so you're editing the same document with both data sources. ignoreRequestParams missing will ignore any properties you define.

Attachment displays twice on notes document

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.

How to disable iNotes for a single mail file

Should be simple, but IBM doesn't make it easy...
How do I NOT use iNotes when accessing a mail file over HTTP.
I would like to access a custom view and form to my mail file, but I cannot seem to bypass iNotes. The server always gives me an iNotes page instead of my form.
If I use an old mail file template, it will work, but somewhere in the newer mail templates there is a 'switch' that says use iNotes.
Obviously I still want HTTP, just not iNotes on this one mail file -- I do not want to use an old email template. Where is the 'switch?'
Thanks in advance.
You can force the "classic" ui by adding an URL parameter:
hxxp://yourserver.yourdomain.com/mail/mailfile.nsf?OpenDatabase&ui=webmail
Same works for opening a view:
hxxp://yourserver.yourdomain.com/mail/mailfile.nsf/YourView?OpenView&ui=webmail
If you want to completely disable iNotes for a mailfile without URL hacking, then you can delete the "link" to the corresponding FormsX.nsf- File. This link is stored in the database icon. The icon document contains an item called $FormsTemplateFile.
This "context" has been reveiled, when something went wrong with the german templates in R9 that still pointed to Forms85.nsf. Check this link at IBM for details. The code in that link can also be used to solve your problem by removing the "linking" item:
Dim sess As New NotesSession
Dim db As NotesDatabase
Dim doc As NotesDocument
Dim item As NotesItem
Dim newFF As String
Dim itemFF As NotesItem
Set db = sess.CurrentDatabase
Dim session As New NotesSession
Dim n As String
Set db = session.CurrentDatabase
n = "FFFF0010"
Set doc = db.GetDocumentByID (n)
' original code from post
'Set itemFF = doc.GetFirstItem("$FormsTemplateFile")
'newFF = Inputbox("Enter new Forms File name", "Change Forms File", itemFF.values(0))
'Set item = doc.ReplaceItemValue("$FormsTemplateFile", newFF)
'new line to fix problem
Call doc.RemoveItem( "$FormsTemplateFile" )
Call doc.save(True,True)
This works, because in every database the Icon has the same fix noteid.
Thanks to Torsten for 2 options.
I may as well describe the solution in detail:
In Domino Designer, open the Icon in the Resources folder for the database.
Click on the Properties tab, select Document IDs, and copy down the Note ID -- in my case the value was 0000011E.
Run the following agent in LotusScript:
Sub Initialize
Dim session As New NotesSession
Dim db As NotesDatabase
Dim iconDoc As NotesDocument
Set db = session.CurrentDatabase
'NoteID of icon document from icon properties
Set iconDoc = db.GetDocumentById("11E")
'Delete the field $FormsTemplateFile
Call iconDoc.RemoveItem("$FormsTemplateFile")
Call iconDoc.Save(True, True)
End Sub
This gets the icon design doc by NoteID from which you can modify any of the fields 'hiding' there. Removing $FormsTemplateFile disconnects the mail file from using iNotes. Cheers.

#Mailsend in xpages button

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.

How to preview form using lotus script

I want to preview the current form and in the preview I can print it, how can I do this in lotus script?
You want to preview currently selected document in a view?
You could use view action that would run something like this:
Sub Click(Source As Button)
Dim w As New NotesUIWorkspace
Dim doc As NotesDocument
Set doc = GetSelectedDoc()
Call w.DialogBox(doc.form(0),True,True,True,True,False,True,"Put your title here",doc,True,True,False)
End Sub
Function GetSelectedDoc() As NotesDocument
'MbĀ¤, 04.04.2005
'The function returns currently selected document
'On Error Goto ErrHandler
Dim s As New NotesSession
Dim db As NotesDatabase
Dim c As NotesDocumentCollection
Set db = s.CurrentDatabase
Set c = db.UnprocessedDocuments
If c Is Nothing Then Exit Function
Set GetSelectedDoc = c.getFirstdocument
'add your error handling
End Function
See here for NotesUIWorkspace.DialogBox param explanation.
Or you can simply use #DialogBox formula:
#DialogBox( form ; [AUTOHORZFIT] : [AUTOVERTFIT] : [NOCANCEL] : [NONEWFIELDS] : [NOFIELDUPDATE] : [READONLY] : [SIZETOTABLE] : [NOOKCANCEL] : [OKCANCELATBOTTOM] : [NONOTE] ; title )
Notes is not really great for printing. Depending on your requirements you might be better off writing code to create a word document, which can then be printed. There are plenty of examples out there for achieving this and here is one of them to get you started: http://searchdomino.techtarget.com/tip/A-flexible-data-export-agent-for-Lotus-Notes
Hope this helps.
Create a subform with a read-only version of the form you want to print.
To preview the form - have the subform display in a Dialog box. Have dialog box set to inherit the values from main document.
On the subform display a print button that will print the read-only document. Have the print button hide when printed.
Have you tried to do a right click on the document? You might be able to print it by doing a right click. I would try the simple things first and see if this meets the user needs.
If you are talking about a workflow where you are handling documents and the process is complete and you want to preview the final document you should be able to do this via the UI Document Classes in either the java side or the NotesUI classes in LotusScript. Once you have a handle to the UIDocument you can do several things..
I would try setting the document to readonly and show it in the Preview pane if that object is in your UI design. You could then query the user if they want to print the document or not and use the UIDocument.print option.

Resources