Lotus Notes Api : On Calendar Entry created/deleted - lotus-notes

I'm not familiar with Lotus Notes.
The task is the following: I need to implement the plug in which listen "Calendar Entry created/deleted" event. And send this scheduling (iCal) data to some web service so that it could be synchronized in the another system.
I would appreciate if somebody could give me some vector, where I need to find solution, how to subscribe to such an event?
Thanks

You need to look into agents, specifically the type that runs when documents are created / modified. For deletes look at the QueryDocumentDelete event on the database. Between those two code points you can add the necessary logic to respond to calendar (or other) document creation and deletion.
You'll have to check the documents form to determine if the document being acted upon is a calendar event, but after that it should be straightforward.
Note there can be a delay between when a document is created and when the agent runs.
UPDATE:
Within the agent, you'll need to get the unprocessed documents collection from the database object and operate on that. Using LotusScript it would look like this:
Dim s as New NotesSession
Dim db as NotesDatabase
Dim docCollection as NotesDocumentCollection
Set db = s.CurrentDatabase
Set docCollection = db.UnprocessedDocuments
Then from there you can loop over the document collection and process each NotesDocument object.

Related

Lotus Notes - Script or formula to create multiple new documents within a database

I have the following situation:
currently an end user needs to create several documents using a step by step process, but with some new features that was created, the user will need to create more required documents.
I am afraid they will forget to create an important one that will mess the process at the end.
Based on this I was thinking to create a script, since the Compose #Command (Formula Language) allows me to create only one form.
Note that these documents will have computed fields, so no need to fill any data on these new forms.
Here is what I got so far, it is working but I think someone could give a better idea. Thanks.
Dim session As New notessession
Dim db As notesdatabase
Dim newdoc As notesdocument
Dim i%
Set db=session.currentdatabase
For i%=1 To 1 'or however many slots you want
Set newdoc=db.createdocument
newdoc.form= "Form1"
Call newdoc.save(True,True)
Set newdoc=db.createdocument
newdoc.form="Form2"
Call newdoc.save(True,True)
Set newdoc=db.createdocument
newdoc.form="Form3"
Call newdoc.save(True,True)
Next i%
End Sub
If you want to make the documents compute as if they were opened in frontend, then you need to tell the code to do that: simple saving a document does NOT do frontend calculations. You need to add a ComputeWithForm before every save to do exactly that: compute the document with the assigned form. That will look like this:
Set newdoc=db.createdocument
newdoc.form= "Form1"
Call newdoc.ComputeWithForm( True, True )
Call newdoc.save(True,True)
Take care: if there is any error in the formulas of your form because you forgot to fill some essential field, then the compute will not complete and only fields above the one that had the error will be calculated. In addition this funcion may throw an Error if something goes wrong that you have to catch in your code (depends of parameters, check documentation)

Override Authors Field and allow access to some fields. Lotus Notes

I have a Notes Form containing many fields, tabbed tables, embedded views etc. Editing access is restricted to a small group via an Author field and the ACL to prevent changes to most of the data. However, I also need to allow editing of one or two fields to a wider user group. In essence the opposite to what one can do with Controlled Access Sections.
A move to XPages on this one is not a realistic option in this instance.
I know it is probably a non-starter but any help would be appreciated.
I would also follow the path that Richard describes in his respons, but without the delay. Write an agent, that Runs on behalf of a person / server who is allowed to edit everything in that database.
Then create a form that you open in a dialog that the user can fill and call the agent with runonserver.
Example code might look like this:
Dim ws as New NotesUIWorkspace
Dim ses as New NotesSession
Dim db as NotesDatabase
Dim ag as NotesAgent
Dim docTmp as NotesDocument
Dim strID as String
Dim varOK as Variant
Set db = ses.CurrentDatabase
Set ag = db.GetAgent( "RunMeOnServerOnBehalfOfSomeone" )
Set docTmp = new NotesDocument( db )
call docTmp.ReplaceItemValue( "ChangeUNID", docToEdit.UniversalID )
varOK = ws.Dialogbox( "YourSpecialDialogForm", True, True, False, False, False, False, "Enter values", docTmp, True, False, True )
If not varOK then exit sub
Call docTmp.Save( True, True, True ) '- runonserver cannot be called with a notesdocument that is unsaved
strId = docTmp.NoteID
Call ag.RunOnServer( strID )
In the agent you read the unid of the document to change and write the values from the docTmp to the target document.
Don't forget to cleanup the docTmp in the agent or in the code later.
of course you can use "reusable" parameter documents or one document per user. depending on how often this function ist needed.
But this seems to be a bit of a stretch (you need to keep track in your agent WHO requested a change, as all documents will be saved by the signer of the agent and not the user himself.
Probably a better solution would be to ADD the users to the author- field of the document and simply PROTECT everything else in the document with access controlled sections. You can completely hide those section headers and everything so that nobody can collapse them or if you don#t like the look of them.
There's no way to allow users without Author access the ability to directly edit part of the document. The only option I can think of would be to give them the ability to click a button that allows them to type their changes into a new temp document (using a form that only contains the fields that you want to expose), and set up an agent that runs when docs are created or modified that reads those documents copies the data from them back into the original document. There can be a bit of a delay before the changes are applied, though, so you'll have to warn users of that.

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.

Find dead doc link in Lotus Script

I have a database and also doc links, I am trying to access those doc link through web. I have found the method appendDocLink in the help. Looked through all the NotesRichTextItem, Document and NotesDocument properties and methods, but there's nothing to check dead link.
What I am trying to do is get all the doclinks in lotus script, and then check to see if they lead to an existing doc or if its a dead link. If yes then will send a mail to the admin about the dead link. All these things I want to happen using a schedule agent.
You need to traverse the NotesRichTextItem using NotesRichTextNavigator and find the elements of type NotesRichTextDocLink.
Dim rti As NotesRichTextItem
Dim rtnav As NotesRichTextNavigator
Dim rtlink As NotesRichTextDocLink
Set rti = doc.GetFirstItem("Body")
Set rtnav = rti.CreateNavigator
If Not rtnav.FindFirstElement(RTELEM_TYPE_DOCLINK) Then
Messagebox "No doclinks in Body item",, "No doclinks"
Exit Sub
End If
Do
Set rtlink = rtnav.GetElement
'Use rtlink.DocUNID to get document UNID and try to fetch the document
Loop While rtnav.FindNextElement
I am not sure whether creating new NotesDocument object from rtlink.DocUNID would result in error or NOTHING (in case document with that UNID is not present). You will have to check that yourself.
The above code snippet has been taken from here and modified for this answer.

Difference in doc created by agent vs gui QuerySave fails to allow ODBC transfer

After I create a doc in a Notes app, I'm moving information from that doc to a postgres db.
The agent that transfers the data to postgres uses a field in the doc as the key field.
I'm running into the following problem:
- If I create the doc via the Notes client, the transfer occurs without problems.
- If I create the doc from an agent (which processes an incoming email and generates a valid key field value), the transfer fails with a null key error. If I then open and save the doc, the transfer is successful.
I key field value is not null, however. I can see it in the view, in the document, and in the document properties.
Any thoughts on how I might be able to figure this out would be appreciated.
thanks!
clem
============================
Thanks Torsten for the reply. I appreciate it. Well, there's not much to the code, really. Here's part of it. "x.LogNumber" returns a string. The format is something like T1234CP. I ended up adding the computeWithForm and setting the IsSummary tho I don't think it was necessary.
atdoc.logNumber = x.LogNumber
Call atdoc.computeWithForm(false, false)
Dim lnItem As NotesItem
Set lnItem = atDoc.getfirstitem("logNumber")
lnItem.IsSummary=True
Call atdoc.save(True, False)
=======================================
Once the doc is created, an agent runs that transfers some data from the doc to the postgres db via odbc:
'.. define the 'key field' to be use in the connection.select call
Dim selectFldLst As New LCFieldList
'.. add the key field name to the LCfieldList object.
Call selectFldLst.Append(NotesKeyFieldName, LCTYPE_TEXT)
'.. set this field to be the key field.
selectFldLst.Getfield(1).flags = LCFIELDF_KEY
Set Notes_LCFieldList = New LCFieldList ' flSrc
Set odbcDB_LCfieldList = New LCFieldList ' flDest
'.. get the key of the doc to transfer.
Set docWithTransferID = docsToTransferViewEntry.Document
selectFldLst.LogNumber = Trim(docWithTransferID.stid(0))
count = Notes_LCConnection.Select(selectFldLst, 1, Notes_LCFieldList)
^--- This selects the fields from the Notes document. This is where it fails. It returns 0 for 'count'. It should return 1. If I save the document manually, it works.
Sounds like your form is doing something to it. As a quick and dirty fix you could try doc.computeWithForm() in your agent before saving.
You create the records from Notes? Save yourself the trouble with code in the events and configure DECS. It creates the document for you reliably.
Most probably the items in the document you create do not have the "Summary" property set. That makes them "invisible" for some functions / subs...
Please provide some code about how you create the items. If you do it like Set item = New Item(doc, "Name", "Value") then the item will not be summary. Then you need to call a item.issummary = true
Taking into account the last comments I guess, that the agent sets the item with the wrong datatype. Again: The code of the agent would have helped to identify this.
If for example the Field in the document is of type text and the agent writes something like
docWithTransferID.stid = 1 then everything "seems" to be OK, as the field is shown correctly in the views and in the Form. But in the Properties of the document it will be shown as number. As soon as you save the document, the design of the form will force it to be a Text.
The same thing works vice versa. If the agent reads the data from a textfile (e.g) and does something like docWithTransferID.stid = "1", then the item will be text, no matter how it is defined in the Form. As soon as you save the document -> Voila, it will be a number again.
Background LotusScript does not know ANYTHING about the Form and therefor does not obey datatypes or formats... You have to take care for this yourself.

Resources