lotus notes automation - lotus-notes

Is it possible to automate lotus notes to post a local file to a database? I have a daily task to post a logfile to a notes database. I can gather the logfile via script but don't know enough about notes scripting to figure this out.
I know thrre is a com interface as long as I have the client on the PC, but I can't figure out how to get a file uploaded to a dataase. I can use either vbscript or (preferred) powershell

If you search around the net you'll find examples of using VBScript to manipulate Lotus Notes. Here's one example: http://haveworld.blogspot.com/2006/10/vbscript-and-lotus-notes.html
You'll need to know a little about Lotus Notes to make this work, though. Start small and see if you can even get the Notes Version to appear:
Set oNotesSession = CreateObject("Notes.Notessession") 'create notes session
Msgbox oNotesSession.NotesVersion
If that works, you know you're in good shape. If not, make sure you've installed Lotus Notes correctly and configured it on the client.
The code to post a local file to a database involves connecting to Notes, creating a new Notes Document, adding a file object into the body of the document, and then saving it. You can use any kind of Notes Database to do this, but I'd suggest creating a new one based on the Document Library template, and using that to store your files.
Here is some code that will create a new Notes document, set the subject field, attach a file, and then save the document. This assumes there's a local Notes database already available called "FileStorage.nsf"
strFileName = "C:\Windows\Media\tada.wav"
strSubject = "Your Subject Goes Here"
Set oNotesSession = CreateObject("Notes.Notessession") 'create notes session
Set oDb = oNotesSession.GetDatabase("", "FileStorage.nsf") 'open database on local named FileStorage.nsf
Set oDoc = oDb.CreateDocument
' Filling the fields
oDoc.Subject = strSubject
Set oBody = oDoc.CreateRichTextItem("Body")
oBody.EmbedObject 1454, "", strFileName '1454 = Embedded Attachment type
oDoc.Save False, False

Related

how to get list of Lotus notes mail file's owners name

I wonder if it is possible to generate a list of email users and their owners to a text file? I'm a beginner in Lotus script ... can there be any database in domino administrator where can i find such data? Screen
you can use the NotesDBDirectory class to loop through all dbs on server. If the database resides in subfolder mail, you can get the database using the notes database class. Normally the title of the database is the owners Name. But you can also get the calendar Profile document and read the field owner.
Another approach: take a look in names.nsf. you can Export data as CSV-file ...
Greetz, Markus
Code example:
Dim sess as new Notessession
Dim dbdir as NotesDBDirectory
Dim db as NotesDatabase
Dim Profile As NotesDocument
Set dbdir = New NotesDBDirectory("Servername")
Set db = dbdir.GetFirstDatabase(1247)
Do until db is nothing
'expecting the mail files are located in subfolder mail, check the path
If Ucase(Left(db.FilePath , 5)) = "MAIL\" Then
If not db.IsOpen Then
Call db.Open("","")
End If
Set Profile = db.GetProfileDocument("CalendarProfile")
Print Profile.Owner(0) ' prints out the owner name to Client Status bar or Server console
End If
Set db = dbdir.GetNextDatabase
Loop
The line
Print Profile.Owner(0) ' prints out the owner name to Client
must be modified to match your needs. You can use the Lotus script write Statement.
Take a look at IBM help Center:
https://www.ibm.com/support/knowledgecenter/en/SSVRGU_9.0.1/basic/H_NOTESDBDIRECTORY_CLASS.html
https://www.ibm.com/support/knowledgecenter/en/SSVRGU_9.0.1/basic/H_NOTESDATABASE_CLASS.html
https://www.ibm.com/support/knowledgecenter/de/SSVRGU_9.0.0/com.ibm.designer.domino.main.doc/LSAZ_WRITE_LB_STATEMENT.html
HTH, Markus
I'd iterate through the user documents in the server's names.nsf. Look at each user to see if they have an email database listed and, if so, output them to a text file.

Lotus Script - Send email does not attach form

I am trying to send email from Lotus Script. But the email doesn't seem to have the FORM ( named Email Form , referred below in the code ) attached to it, when received in the inbox.
When I check the Document property in the email, it says the form is "Memo" and the FROM, TO addresses are Blank.
I have defined the FROM, TO,SUBJECT,BODY fields in the Email Form in a specific format .
But all these field values are populated correctly in the form. Issue happens only after send .
The Same code works fine in some other Lotus Notes, when the email is triggered by another person, having a different Notes ID configured in that system .
Not sure if this is code issue, or Lotus Notes configuration issue .
Any help to solve this would be greatly appreciated . The for has the property " Store Form in Doc" set and even ComputeWithForm returns success .
Could this be a problem with my Lotus notes settings/configuration? .Same code sends email in correct format in some other system configured wit their Notes ID
Here is a sample code on the EMAIL Action button
Sub Click(Source As Button)
Set email = db.CreateDocument
Call email.ReplaceItemValue("Form", "Email Form")
Call email.ReplaceItemValue("Subject", " My TestEmail")
Call email.ReplaceItemValue("From", nom.Canonical)
Call email.ReplaceItemValue("SendTo", nom.Canonical)
Call email.ReplaceItemValue("Body", " Hello, my test email ")
Call email.Send(True,nom.Common)
End Sub
It seems you mixed syntax here, you both set SendTo and specify nom.common, only one should be done. As in the help you should use:
Dim session As New NotesSession
Dim db As NotesDatabase
Dim doc As NotesDocument
Set db = session.CurrentDatabase
Set doc = New NotesDocument( db )
doc.Form = "Email Form"
doc.SendTo = "Elissa Minty"
doc.Subject = "Here's the document you wanted"
Call doc.Send( true ) 'true here means you the form is stored and sent along with the document.
Now, check that you "Allow use of stored forms in this database." in your DB, could it be that this code exists in differents DBs and one doesn't have "Email Form" ? BTW check is it really "Email Form" and not "Email" ?
You may need also to check the local configuration on the client. To do this refer to Help.
Its not that complicated to send mails usually, with docs from a Mail Enabled database. But now you have added a more complicated solution, than necessary, you may want to review your solution, to save yourself of future problems.
You won't even need to LotusScript this, provided the Mail fields (SendTo as minimum) is there on the document.
See here how:
Designer 8.5.3 Help - Setting up automatic mailing

Can't migrate RichText to RichText in XPages

I have an old Notes Client application. On the form are two RichText fields that hold attachments. JPG's, PDF's, whatever. The document also contains a unique key and other meta-data.
What I want to do is migrate from having multiple attachments on a document to a new document for each attachment. I've never done much with embedded objects and even less with MIME.
I'm currently working in XPages Java but could go to LotusScript if need be.
I was working with this snippet:
List<EmbeddedObject> docPicture = this.getFileAttachments(doc, "picture");
List<EmbeddedObject> docPDF = this.getFileAttachments(doc, "pdf");
for (EmbeddedObject eoPic : docPicture) {
picCount++;
Document newDoc = currentDatabase.createDocument();
newDoc.replaceItemValue("form", "fm_file");
newDoc.replaceItemValue("uploadToken", doc.getItemValueString("barCodeHuman"));
newDoc.replaceItemValue("fileName", eoPic.getName());
newDoc.replaceItemValue("size", eoPic.getFileSize());
fileName = eoPic.getName();
fileType = fileName.substring(fileName.length() - 3);
newDoc.replaceItemValue("type", this.getMIMEType(fileType));
// Extract Attachment and Add To Attachment Document
InputStream attachInputStream = eoPic.getInputStream();
Stream attachStream = session.createStream();
attachStream.setContents(attachInputStream);
MIMEEntity attachField = newDoc.createMIMEEntity("attachment");
MIMEHeader attachHeader = attachField.createHeader("content-disposition");
attachHeader.setHeaderVal("attachment;filename=\"" + eoPic.getName() + "\"");
attachField.setContentFromBytes(attachStream, this.getMIMEType(fileType), MIMEEntity.ENC_IDENTITY_BINARY);
Note I'm using the OpenNTF API but could go back to the lotus objects if need be.
Anyway - this almost worked. I got my documents - 1 per attachment. But when going into the field "attachment" in the document propertied it's not a RichTextField it's a MIME something. that's causing me probably with the next phase of my project. The RichTextDocuments work fine but not the MIME ones.
this is a 1 time migration need so any thoughts on how I can end up with RichTextFields would be appreciated. Thanks!!
try to not involve mime entities at all.
as Oliver said, check your target richText field on the form does not have the 'store contents as mime' checked.
you could even use a richText lite field and restrict it to attachments.
I think you might be using the MIMEEntity method setContentsFromStream because you want to directly move the attachment from doc to doc?
if you want to move using just RichText embedded objects (no mime entity involvement) you need to extract the embeddedObject using .extractFile to the file system first.
Then using the RichTextItem that you create on the new doc (instead of create mime entity) you can use rti.embedObject to attach the file you extracted. (probably best to delete the temporary extract file after successful migration), see the designer help for an example of the parameters required for embedding attachments.
when extracting the file to file system you could extract it to the JVM's temporary directory, the file on the file system needs to have the same file name that you want it to have when attached to the new document.
for this reason you can't really use File.createTemporaryFile() because your temp file name will have random characters in it. instead you
you can get the temp directory with
System.getProperty("java.io.tmpdir")`
and the use that in your extract filepath.
another thing to check before starting processing, is the current notesSession's isConvertMIME setting, if to source field is mime, session.isConvertMIME == true will convert the field to richText when loading the doc. I think in xpages it is false by default, though I don't think it will affect you because I think your source attachments are already richText but for someone reading this and using mime source field it would be important to note. also if you change this using setConvertMIME, be sure to change it back to what it was when you finish your processing.

Lotus Notes document to PDF

I need some help since I do not know where to start. Ideally, I would like to have a button that can convert my Lotus Notes document to a PDF file, then it will open up a new email then take the email address in that document to the "To" filed. At this point we use CutePDF writer to create the PDF file. I break down the process like the one below:
Print a document
User choose CutePDFwriter
Save the pdf file
Compose a new email with the email address that is on the Notes document placed on the 'To' field
Can anyone help me starting on this?
If you're happy to let the user select cutepdf as the printer, you should be able to get away with using #Commands in a button from the either the document or a view containing the documents (Check the notes designer help).
The only issue I can see is that the user will be able to change the path that cutepdf prints to, so you will have to make the user find the attachment again (but you will be able to automate the attachment dialog coming up).
Got my answer from Domino Designer help file. Use the code below to open up mail file
Dim workspace As New NotesUIWorkspace
Dim uidoc As NotesUIDocument
Set uidoc = workspace.CurrentDocument
Dim doc As NotesDocument
Dim item As NotesItem
Set doc = uidoc.Document
Set item = doc.GetFirstItem("QSContactEMail")
Set uidoc = workspace.ComposeDocument _
(mailserver$, mailfile$, "Memo")
Call uidoc.FieldAppendText("EnterSendTo", "Test")
For the printing I just call the print function and let the user choose CutePDF writer

Using VBA to read the metadata or file properties of files in a SharePoint doc library

I have a few hundred Word templates (DOTX) on a SharePoint site. Many teams of users work with these templates.
When a user needs to customize this documentation, they click a special link on SharePoint to generate a new document (DOCX) from the template they choose. This new document file always needs to be "linked" back to its template file on SharePoint. If the document loses that link, it won’t work correctly and is considered “broken”.
When documents break, I need to re-establish the link back to the right template on SharePoint. It makes sense to do this programmatically so I can distribute the solution to my team.
I want to give each template file a unique Template ID (a three-digit number), stored in metadata or a custom file property. When new documents are generated from the templates, the Template ID automatically carries over into the document, so that’s set. Now I just need to use VBA to scan the template files in the SharePoint document library for the matching Template ID. When that’s found, I can re-establish the link and all is well.
I’m basically looking for this:
Sub DocFixer()
Dim objTemplate as Template
Dim objBrokenDoc as Document
Set objBrokenDoc = ActiveDocument
For each objTemplate in "\\SharePoint\Template Library\".Templates
If objTemplate.Properties("Template ID").Value = objBrokenDoc.Properties("Template ID").Value Then
objBrokenDoc.AttachedTemplate = objTemplate.Path
Exit For
End If
Next
End Sub
…but I’m having trouble using VBA to read SharePoint doc library contents without actually opening the contents, as that takes far too long with so many templates, plus its very disruptive for the user.
Any ideas? Could you point me in the right direction?
Edit: Here's my solution:
Sub Macro()
Dim FSO As Object
Set FSO = CreateObject("Scripting.FileSystemObject")
Dim objFile As Object
Dim objDSO As Object
For Each objFile In FSO.GetFolder("\\SharePoint\doc lib\").Files
Set objDSO = CreateObject("DSOFile.OleDocumentProperties")
objDSO.Open objFile.Path
If objDSO.CustomProperties.Item("Template_ID") = ActiveDocument.CustomDocumentProperties("Template_ID").Value Then
ActiveDocument.AttachedTemplate = objFile.Path
End
End If
Next
MsgBox ("No matching template found. Please attach the proper template manually."), vbCritical
End Sub
Apparently this taps into DSOFile.dll (http://technet.microsoft.com/en-us/library/ee692828.aspx), but I didn't have to add the reference? Still confused on that part.
Also, this might not work over https:// (SSL). Worked for me though, so I thought I'd share.
I would start by calling the SharePoint web services from VBA.
Once there you can make a call to GetListItems that will pull back the document with the correct TemplateID attribute directly.

Resources