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

padillrrIT DirectorAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
padillrrIT  DirectorAuthor Commented:
havne't tried but I can....
0
padillrrIT  DirectorAuthor 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
Amazon Web Services

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

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
padillrrIT  DirectorAuthor 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
padillrrIT  DirectorAuthor 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
padillrrIT  DirectorAuthor 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
padillrrIT  DirectorAuthor 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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Lotus IBM

From novice to tech pro — start learning today.