[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 301
  • Last Modified:

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!
0
irene79
Asked:
irene79
  • 7
  • 6
  • 4
2 Solutions
 
Sjef BosmanGroupware ConsultantCommented:
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?
0
 
mssturgeonCommented:
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
0
 
mssturgeonCommented:
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)))
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
irene79Author Commented:
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!
0
 
Sjef BosmanGroupware ConsultantCommented:
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.
0
 
irene79Author Commented:
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?
0
 
mssturgeonCommented:
You would first need a Rich Text Field on the new document ... like:

     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
     Dim rtitem as NotesRichTextItem

     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)))
     Set rtitem = New NotesRichTextItem( newDoc, "Body" )
     Call rtitem.AppendDocLink( thisDoc, thisDoc.Subject(0) )

You may need to Reload the uidoc to get it to show ... not sure.

Cheers,

- Shane
0
 
Sjef BosmanGroupware ConsultantCommented:
Does reloading a form with a rich-text field work?? I'd postpone the EditDocument (I don't like FieldSetText at all), and do everything in the NotesDocument, like this:

     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
     Dim rtitem as NotesRichTextItem

     Set thisDoc = ws.CurrentDocument.Document
     Set otherDB = New NotesDatabase("", "test.nsf")
     Set newDoc = otherDB.CreateDocument()
     newDoc.Form = "FormName"
     Call newDoc.ReplaceItemValue("Channel", "Email")
     Call newDoc.ReplaceItemValue("Source", "Public")
     Call newDoc.ReplaceItemValue("EmailAddress", thisDoc.From(0))
     Call newDoc.ReplaceItemValue("EmailSubject", thisDoc.Subject(0))
     Call newDoc.ReplaceItemValue("Received", Cstr(thisDoc.DeliveredDate(0)))
     Set rtitem = New NotesRichTextItem( newDoc, "Body" )
     Call rtitem.AppendDocLink( thisDoc, thisDoc.Subject(0) )
     Set uidoc = ws.EditDocument(True, newDoc)

Don't know if that matters much... not sure.
0
 
irene79Author Commented:
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!
0
 
mssturgeonCommented:
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)?
0
 
irene79Author Commented:
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!
0
 
Sjef BosmanGroupware ConsultantCommented:
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")
0
 
irene79Author Commented:
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)

0
 
Sjef BosmanGroupware ConsultantCommented:
>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.
0
 
irene79Author Commented:
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!
0
 
irene79Author Commented:
oopz saw it already.

      Set uidoc = ws.EditDocument(True, newDoc)
      Call uidoc.FieldSetText("Contri_Name", "testing")
0
 
Sjef BosmanGroupware ConsultantCommented:
> 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 :)
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 7
  • 6
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now