?
Solved

Copyallitems from mail memo into new doc in mail in db

Posted on 2008-11-19
13
Medium Priority
?
1,362 Views
Last Modified: 2013-12-18
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
Comment
Question by:padillrr
  • 6
  • 5
  • 2
13 Comments
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 23000005
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
 

Author Comment

by:padillrr
ID: 23000016
havne't tried but I can....
0
 

Author Comment

by:padillrr
ID: 23000050
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 5

Expert Comment

by:mekhet30
ID: 23001527
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
 

Author Comment

by:padillrr
ID: 23001631
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
 
LVL 5

Expert Comment

by:mekhet30
ID: 23001667
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
 
LVL 5

Expert Comment

by:mekhet30
ID: 23001673
sorry i mean a field called Body not Memo
0
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 23002113
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
 
LVL 5

Expert Comment

by:mekhet30
ID: 23002221
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
 
LVL 5

Expert Comment

by:mekhet30
ID: 23002272
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
 

Author Comment

by:padillrr
ID: 23006201
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
 

Author Comment

by:padillrr
ID: 23006409
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
 

Accepted Solution

by:
padillrr earned 0 total points
ID: 23009027
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

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

You’ve got a lotus Domino web server, and you have been told that “leverage browser caching” is a must do. This means that we have to tell the browser everywhere in the web to use cache. In other words, we set (and send) an expiration date in the HT…
  In today’s Arena we can’t imagine our lives without Internet as we are highly used to of it. If we consider our life style just for only 2 min we found that face to face communication is swapped by e-communication.  Every Where from Works place to…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question