• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1384
  • Last Modified:

Copyallitems from mail memo into new doc in mail in db

The following code is doing just about everuthing except that the BODY of the original replay message is not being copied into the new document. This script is running on a querysend of a reply form. The intent is to copy the make a new copy of the reply in a mailin db. It does create the new document and keeps MOST of the subject line but the entire body of the reply is missing. When i check the properties of the newly created document on the mainin db the body is missing. It's basically a method for filing emails and replies. On the memo creation I email the document into the main in db which works fine but emailing a reply DOES NOT work so I've tried to create a new doc with all the items from the source document and it doesn't get the body field from the original reply ....................
Sub Querysend(Source As Notesuidocument, Continue As Variant)
	
	Dim sess As New NotesSession
	Dim ws As New NotesUIWorkspace
	Dim db As NotesDatabase, jobcorDB As NotesDatabase
	Dim doc As NotesDocument, memo As NotesDocument
	Dim customerJob As Variant, sentBy As Variant, recipients As Variant
	Dim subject As String, customerName As String, jobNumber As String, h As String, mailSort As String
	Dim Body As String
	
	' validate form
	Set db = sess.CurrentDatabase
	Set doc = Source.Document
	customerJob = doc.GetItemValue("CustomerJob")
	If (customerJob(0) = "To file please select a job here") Then
		Continue = False
		Exit Sub
	End If
	
		' parse customer job to get new job numbers
	Forall vi In customerJob
		h = Strtoken(vi, " | ", 1)
		If (jobNumber <> "") Then jobNumber = jobNumber + ";"
		jobNumber = jobNumber + Strtoken(h, ":", 2)
	End Forall
	
	'modify subject line
	Call source.FieldAppendText("Subject"," [" & JobNumber$ & "]")
	doc.Subject = subject + " [" + jobNumber + "]"
	customerName = Trim(Strleft(customerJob(0), "-"))
	doc.Customer = customerName
	
		' compose new memo in jobcor db
	Set jobcorDB = New NotesDatabase("domino1/dalinalaw","jobcor2.nsf")
	Set memo = New NotesDocument(jobcorDB)
	Call doc.CopyAllItems(memo, True)
	'memo.body = doc.body	
	memo.Company = customerName
	memo.Form = "Memo" 
	If (doc.GetItemValue("Principal")(0) = "") Then sentBy = doc.GetItemValue("From") Else sentBy = doc.GetItemValue("Principal")
	recipients = Arrayappend(doc.GetItemValue("SendTo"), doc.GetItemValue("CopyTo"))
	recipients = Arrayappend(recipients, sentBy)
	mailSort = "Internal"
	Forall c In recipients
		If (Instr(c, "dalinalaw") = 0) Then
			mailSort = "Client"
			Exit Forall
		End If
	End Forall
	memo.MailSort = mailSort
	Call memo.RemoveItem("$REF")
	Call memo.Save(True, False)
	
	'update Filed status on current doc
	doc.Filed = "Yes"
	Call doc.Save(True, False)
	
'End If
	
End Sub

Open in new window

0
padillrr
Asked:
padillrr
  • 6
  • 5
  • 2
1 Solution
 
Sjef BosmanGroupware ConsultantCommented:
I suppose doc isn't saved yet, so the rich text field Body doesn't really exist yet. Could you try to copyall AFTER the doc.save ??
0
 
padillrrProject CoordinatorAuthor Commented:
havne't tried but I can....
0
 
padillrrProject CoordinatorAuthor Commented:
That didn't work.....I've tried just about everything, even tried grabbing the mime field with the body and appendeding it with no luck. I seems straight forward copyallitems create the new doc and save?!?! What am I missing?
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
mekhet30Commented:
CopyAllItems ignores the RT fields and does not pull over properly

Use the CopyItemToDocument method.

Add the following code

Dim itema as NotesItem

Set itema = doc.getfirstitem("Body")
Call itema.CopyItemToDocument(memo, "Body")


That should do the trick

Cheers
0
 
padillrrProject CoordinatorAuthor Commented:
I'm getting object variable not set on this line:
Call itema.CopyItemToDocument(memo, "Body")
I think if I can get that resolved it will solve the major part of my problem
0
 
mekhet30Commented:
Where in the code did you place the Call itema.CopyItemToDocument(memo, "Body")

I needs to be after Set memo = New NotesDocument(jobcorDB)
and Set doc = Source.Document

also you are certain the doc has a field called Memo on it.  Object variable not set means that ItemA was not set with the Memo field on Doc
0
 
mekhet30Commented:
sorry i mean a field called Body not Memo
0
 
Sjef BosmanGroupware ConsultantCommented:
So even after the doc.Save, it doesn't work. I was already afraid of that, the document really needs to be reopened for the rich-text to be correctly "settled" in the document. If the CopyItemToDocument doesn't work either, for the same reasons probably, add the following lines after the doc.Save:

Dim id As String
id= doc.UniversalID
Set doc= Nothing
Set doc= db.GetDocumentByUNID(id)

and then do your copy/mail stuff.

Another thought: do you want do save the memo-document? If not, why not just use the current document, add the fields you need for sending, send the current document, and remove the fields you added, and finally save the document? No need to CopyAll or CopyItem etc., no problems with rich text, what a relief... :-P
0
 
mekhet30Commented:
Ah - another thing i see in the code

You are setting the doc from uidoc.  You will need to save the uidoc before you compose the memo form especially if you are adding values to the Body before this code executes.  You cannot use the values on the uidoc until the uidoc is saved, if it is a new doc or if values are changed. The notesdocument class will not pick up the values like the NotesUIDocument class.  

Do a Call uidoc.save and Call doc.save(False, False) before the following lines in your code
>>customerJob = doc.GetItemValue("CustomerJob")

Question - why are you doing this in the queriesend event?  Will it not be easier to do from a button on the Form?  

Cheers
0
 
mekhet30Commented:
Sorry - i'm losing focus here.

Do a call source.save before you set doc = source.document

The object variable not set error is received because the Body is not an item when the code runs
0
 
padillrrProject CoordinatorAuthor Commented:
Wow, got a little confused I've posted my code, still getting errors attemt to execute nested  commands and uidoc save cancelled. This is just basically an automatic filing of emails and replies. The original message is being emailed into the mailin db (jobcor) but the rely is causing the issues. I can't email it into the db it seems to go but the doc does not appear in the db. That's why I am trying to create a copy of the doc in the mail in db.....It's crunch time...
Sub Querysend(Source As Notesuidocument, Continue As Variant)
	
	Dim sess As New NotesSession
	Dim ws As New NotesUIWorkspace
	Dim db As NotesDatabase, jobcorDB As NotesDatabase
	Dim doc As NotesDocument, memo As NotesDocument
	Dim customerJob As Variant, sentBy As Variant, recipients As Variant
	Dim subject As String, customerName As String, jobNumber As String, h As String, mailSort As String
	Dim itema As NotesItem
	Dim body As String
	Dim id As String
	
	' validate form
	Set db = sess.CurrentDatabase
	Set doc = Source.Document
	customerJob = doc.GetItemValue("CustomerJob")
	If (customerJob(0) = "To file please select a job here") Then
		Continue = False
		Exit Sub
	End If
	
		' parse customer job to get new job numbers
	Forall vi In customerJob
		h = Strtoken(vi, " | ", 1)
		If (jobNumber <> "") Then jobNumber = jobNumber + ";"
		jobNumber = jobNumber + Strtoken(h, ":", 2)
	End Forall
	
	'modify subject line
	Call source.FieldAppendText("Subject"," [" & jobNumber & "]")	
	doc.subject = Subject + " [" + jobNumber + "]"
	customerName = Trim(Strleft(customerJob(0), "-"))
	doc.Customer = customerName
	
	'Call doc.Save(False, False)
	
	Call source.save
	
	id= doc.UniversalID
	Set doc= Nothing
	Set doc= db.GetDocumentByUNID(id)
	
	' compose new memo in jobcor db
	Set jobcorDB = New NotesDatabase("domino1/dalinalaw","jobcor2.nsf")
	Set memo = New NotesDocument(jobcorDB)
	Set itema = doc.getfirstitem("Body")	
	Call doc.CopyAllItems(memo, True)
	Call itema.CopyItemToDocument(memo, "Body")
	memo.body = body
	memo.Company = customerName
	memo.Form = "Memo" 
	If (doc.GetItemValue("Principal")(0) = "") Then sentBy = doc.GetItemValue("From") Else sentBy = doc.GetItemValue("Principal")
	recipients = Arrayappend(doc.GetItemValue("SendTo"), doc.GetItemValue("CopyTo"))
	recipients = Arrayappend(recipients, sentBy)
	mailSort = "Internal"
	Forall c In recipients
		If (Instr(c, "dalinalaw") = 0) Then
			mailSort = "Client"
			Exit Forall
		End If
	End Forall
	memo.MailSort = mailSort
	Call memo.RemoveItem("$REF")
	Call memo.Save(True, False)
	
	'update Filed status on current doc
	doc.Filed = "Yes"
	Call doc.Save(True, False)
'End If
	
End Sub

Open in new window

0
 
padillrrProject CoordinatorAuthor Commented:
Hey Guys, is there an easier way to do this?!?!? It was simple with the original message I thoguht I would be able to use the same code posted below. Am I missing something when, does the reply cause the issue? I've posted the code I have on the querysend of the memo maybe that will help
If source.Document.HasItem("ActionInProgress") Then
		source.Document.RemoveItem("ActionInProgress")
	End If
	If source.Document.CustomerJob(0) = "To file please select a job here" Then
	Else	
		'Messagebox "Modify Subject"
		CustomerName$ = Trim(Strleft(source.Document.customerjob(0),"-"))
		v= source.Document.customerjob 
		JobNumber$= ""
		Forall vi In v
			h$= Strtoken(vi, " | ", 1)
			If JobNumber$<>"" Then JobNumber$= JobNumber$ + ";" ' 
			JobNumber$= JobNumber$ + Strtoken(h$, ":", 2)
		End Forall  
		If Instr(source.Document.subject(0)," [" & JobNumber$ & "]") = 0 Then
			Call source.FieldAppendText("Subject"," [" & JobNumber$ & "]")
		End If
		If Instr(source.Document.EnterBlindCopyTo(0),"jobcorrespondence@mail.com]") = 0 Then
			Call source.FieldAppendText("EnterBlindCopyTo",",JobCorrespondence@mail.com")
		End If
		Call Source.FieldSetText("Customer",CustomerName$)
		Call source.Document.ReplaceItemValue("Filed", "Yes")
		Call source.Document.Save(True, False)
		
	End If

Open in new window

0
 
padillrrProject CoordinatorAuthor Commented:
The JobCor db view was not set to view response docs once I did that the last bit of code  iposted worked...Thanks Guys
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

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