Link to home
Start Free TrialLog in
Avatar of irene79
irene79

asked on

Re: Creating and Displaying new notes document from another database

Hi,

I have a mail database and I will like to take some details and assigned it to a new document from another database.

Upon clicking that agent, a new document from another database will be opened and the fields will be populated with the fields from the mail database.

Fields needed are:
- Channel (by default set to "Email")
- Source (by default as "Public")
- email address (Sender of the email)
- Email subject (Subject of the email)
- Date and Time Received (Date and Time the email is received.)

The new document will be populated with the above value. The user will then fill up the rest of the details and then click on the save button to generate the case id.

Can anyone provide me with the code? Thanks!
Avatar of Sjef Bosman
Sjef Bosman
Flag of France image

Why not copy/paste a mail in the other database? And an agent triggered on When documents have been pasted, which modifies the document the way you want it?
Avatar of mssturgeon
mssturgeon

Assuming your document is open (ie. you are reading said email):

Dim session as New NotesSession
Dim ws as NotesUIWorkspace
Dim uidoc as NotesUIDocument
Dim thisDB as NotesDatabase
Dim otherDB as NotesDatabase
Dim newDoc as NotesDocument

Set thisDoc = ws.CurrentDocument.Document
Set otherDB = New NotesDatabase("server", "database.nsf")
Set newDoc = otherDB.CreateDocument()
Set uidoc = ws.EditDocument(True, newDoc)
Call uidoc.FieldSetText("Channel", "Email")
Call uidoc.FieldSetText("Source", "Public")
Call uidoc.FieldSetText("EmailAddress", thisDoc.From)
Call uidoc.FieldSetText("EmailSubject", thisDoc.Subject)
Call uidoc.FieldSetText("Received", thisDoc.DeliveredDate)



That should do it ...

-- Shane
Some minor alterations:

      Dim session As New NotesSession
      Dim ws As New NotesUIWorkspace
      Dim uidoc As NotesUIDocument
      Dim thisDB As NotesDatabase
      Dim otherDB As NotesDatabase
      Dim newDoc As NotesDocument
      
      Set thisDoc = ws.CurrentDocument.Document
      Set otherDB = New NotesDatabase("", "test.nsf")
      Set newDoc = otherDB.CreateDocument()
      newDoc.Form = "FormName"
      Set uidoc = ws.EditDocument(True, newDoc)
      Call uidoc.FieldSetText("Channel", "Email")
      Call uidoc.FieldSetText("Source", "Public")
      Call uidoc.FieldSetText("EmailAddress", thisDoc.From(0))
      Call uidoc.FieldSetText("EmailSubject", thisDoc.Subject(0))
      Call uidoc.FieldSetText("Received", Cstr(thisDoc.DeliveredDate(0)))
Avatar of irene79

ASKER

Hi,

Can I include the doc link of the email to the newDoc? Can I search and open an document from otherDB based on the subject title? E.g. if subject has case id of XXXX, the agent will search and open document with case id XXXX. Thanks!
1) Yes, you can, but if the mail is in your database, then the doclink would be to your database, so the intented reader must have Read access to your mail database.
2) Yes, but it's better to store a key, e.g. a keyfield with a name or the document's universal id. They you either have the possibilitiy to open a view and use the keyfield as key, or search directly for the universal id. A link with a universal id will get broken when a document is copied and pasted, whereafter the original is deleted.
Avatar of irene79

ASKER

the email is a generic email account shared by a few users, so they should have no problem accessing that mail in the mail database.

can you provide me with the code for the above?
SOLUTION
Avatar of mssturgeon
mssturgeon

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of irene79

ASKER

yupz i managed to get the doc link after i save the document. otherwise, it just wouldn't appear. if i go to debug mode, the link appears. If i let it run, the link will not appear.

How about the code for searching and opening an document from otherDB based on the subject title? E.g. if subject has case id of XXXX, the agent will search and open document with case id XXXX.

Thanks!
Just build a view in otherDB sorted by CaseID and use view.GetdocumentByKey($caseID). Are you able to assign CaseID when these are created in otherDB, or would it just be embedded in the subject line?  If it's a standard subject line, you could extract and assign them automatically when the case is created from the email.

What is your specific situation (details/examples, please)?
Avatar of irene79

ASKER

Case id is already created when the doc is saved. Right now, I need to get the case ID out of the subject field and open the document with that case id.

e.g. subject is "My case no. is FB20050519-1 for followup action"

Upon clicking of the agent, i should be able to extract FB20050519-1 and open this document from another database. How to derive FB20050519-1 .. Based on the "FB20" and a space, i will determine what is the case id. and open this document.

Thanks!
Wouldn't it have been a lot easier to have added a CaseID field? It might even be better to correct your database design immediately, by adding the CaseID-field and running an agent that will generate the CaseID-field in existing document, extracting them from the Subject-field. You will absolutely regret it later if you don't correct it now.

How to extract the case-id? That depends. Is the structure of Subject always the same, does it always begin with "My case no. is" and end with " for followup action"? Then its easy:
    cid:= @Left(@Right(subject; "My case no. is "); " for followup action")
Avatar of irene79

ASKER

If i assign the case id when they create the document and they dun save the document, i will have missing numbers because the numbers assigned wasn't used.

There is no standard for subject. It can start and end with anything. As long as it consist of a case id in the subject, the code should be able to extract the id and open the document in edit mode.

I have already written codes to extract the case id, but im not sure how to open the document in the other database (OtherDB) in edit mode.

      Set thisDoc = ws.CurrentDocument.Document
      Set otherDB = New NotesDatabase("Server", "Test.nsf")

      positionOfChar = Instr(thisDoc.Subject(0), "FB20")
      subj = thisDoc.Subject(0)
      
      CaseID = Mid(thisDoc.Subject(0), positionOfChar)
      positionOfChar2 = Instr(thisDoc.Subject(0), " ")
      CaseID = Strleft( CaseID, " ", 5)

>If i assign the case id when they create the document and they dun save the document,
> i will have missing numbers because the numbers assigned wasn't used.
Then assign a case number during the QuerySave, for it is executed just before the document is saved.

> ... but im not sure how to open the document in the other database (OtherDB) in edit mode
Various posts above describe how to do that. See html:Q_21410504.html#13966408 in this question.
Avatar of irene79

ASKER

yes, the case id is created when the user click on the Save button.

The various post is creating a document in the other database. How about opening the document from the other database?

Set view = otherDB.GetView( "ByCaseID" )
Set newDoc = view.GetdocumentByKey(caseID)

How do I open this document in edit mode? Thanks!
Avatar of irene79

ASKER

oopz saw it already.

      Set uidoc = ws.EditDocument(True, newDoc)
      Call uidoc.FieldSetText("Contri_Name", "testing")
> yes, the case id is created when the user click on the Save button
That's not exactly what I meant. If you have code in the Save-button on the screen, and then you call save, the user can still cancel the save. That's why you need to put the generation of the case-id in the QuerySave script, because that cannot (or is very hard to) be interrupted.

As I said, I dislike the FieldSetText calls. I prefer to work with the doc (not uidoc), that's why I always try to prepare the doc before I call EditDocument. In this case:
    Call newDoc.ReplaceItemValue("Contri_Name", "testing")
Place it BEFORE the call to EditDocument.

And thanks :)