Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

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

Modify Subject Line of email on querysend

The following code already modifys the subject line by appending the job ref numbers to the subject of an email, I am using this in a MEMO, now in the reply I want to REPLACE the previous job ref numberrs with the new ones selected. Suggestions please. Obviously the code posted does not work but it is what I am trying to do. I just want to delete the old job ref numbers and replace them with new ones. This is in a REPLY to a memo....Thanks
Sub Querysend(Source As Notesuidocument, Continue As Variant)
	'Check preference and Warn if subject is blank for a new memo
	If source.Document.EnableBlankSubject(0) <> "1" Then
		If source.document.Subject(0) = "" Then
			If Messagebox(warnTxt, MB_YESNO + MB_ICONQUESTION, warnTitle ) = IDNO Then 
				vSubjectBlankSend = False
				Source.GoToField("Subject")
				Call source.Refresh
				Call cMemoObject.SetActionInProgress(MEMO_ACTION_NONE)
				Call Source.Document.ReplaceItemValue("SaveOptions","0")
				cMemoObject. SendBlankSubject=False
				continue = False		
				Exit Sub
			Else
				vSubjectBlankSend = True
				cMemoObject. SendBlankSubject=True
			End If
		End If
	End If
	
	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$ & "]") = 1 Then
			Call source.replaceitemValue("Subject"," [" & JobNumber$ & "]")
			Call source.FieldAppendText("Subject"," [" & JobNumber$ & "]")
		End If
		If Instr(source.Document.EnterBlindCopyTo(0),"jobcorrespondence@dalinalaw.com]") = 0 Then
			Call source.FieldAppendText("EnterBlindCopyTo",",JobCorrespondence@dalinalaw.com")
		End If
		Call Source.FieldSetText("Customer",CustomerName$)
		
	End If
End Sub

Open in new window

0
padillrr
Asked:
padillrr
  • 19
  • 15
1 Solution
 
padillrrProject CoordinatorAuthor Commented:
Points UP! I've tried evaluate and triming the subject line but no luck anyway to do a trim using replaceitemvalue?!?!?
0
 
Bill-HansonCommented:
>> "I just want to delete the old job ref numbers and replace them with new ones."

The only error that I see is on line #37.  ReplaceItemValue is a method of the NotesDocument class, but you are using it with the NotesUIDocument class.  Try changing line #37 to the following line of code.

      Call Source.Document.ReplaceItemValue("Subject", " [" & JobNumber$ & "]")

The line above will replace the subject, not append to it.  If you need to append, then use this line instead.

      Call Source.Document.ReplaceItemValue("Subject", Source.Document.Subject(0) & " [" & JobNumber$ & "]")

Also, line #38 seems redundant.  Is it really necessary?

>> "anyway to do a trim using replaceitemvalue"

Sure.  Trim is a built-in function of the LotusScript language.  To trim any string, just wrap the string in a call to the Trim function.  For example, the first line above would be...

      Call Source.Document.ReplaceItemValue("Subject", Trim(" [" & JobNumber$ & "]"))
0
 
padillrrProject CoordinatorAuthor Commented:
what I'm trying to do is delete the job numbers from the subject line and add the new ones as selected by the sender. i.e.:
Original Subject line when recieved: Blahh [DLG-G0001;DLG-G0003;DLG-R2004]
When I reply I want to reference only one job number so the response should be:
Re: Blahh [DLG-G0001]
The script posted adds the number to the subject line based on a dialog list the sended picks from, when the sender replies the subject line should be modified to display ONLY the new job number the sender selects. I've tried trimming the subject, (Call Source.Document.ReplaceItemValue with "Subject", Trim(" [" & JobNumber$ & "]")) but that didn't work maybe I'm placing it on the wrong line on the script, then I tried replacing the subject line with Call Source.Document.ReplaceItemValue("Subject", " [" & JobNumber$ & "]")
and that didn't work either am I missing something?
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
padillrrProject CoordinatorAuthor Commented:
Well I took a different approach, not one I am happy with but until I can get it working in the query send I just modified the Default value of the subject field with this @Trim(@LeftBack(Subject; "[" it just trims out the job numbers and leaves the RE: subject line....my issue is if there is a [ in the subject line that does not pertain to a job number then that to will be trimmed.....
0
 
padillrrProject CoordinatorAuthor Commented:
now I am having an issue with the replies in that I an get it cleared up unless there's a re: on the email then it just bypasses the formula here is what I'm using:
Subj := @If (Subject = "";Topic;      Subject );
@If(@Contains(Subject;"[");
@If (@Trim(@UpperCase(@Word(Subj; ":"; 1))) = "RE";
            Subj;
      "Re: " + @Trim(@LeftBack(Subject; "[")
      )); @If (@Trim(@UpperCase(@Word(Subj; ":"; 1))) = "RE";
            Subj;
      "Re: " + Subj))
0
 
padillrrProject CoordinatorAuthor Commented:
The following code does some of what I need it to do except that it is only REPLACING some of the Job Ref I need it to completely DELETE the previous Job numbers and add the new ones.....
CustomerName$ = Trim(Strleft(source.Document.customerjob(0),"-"))
		v= source.Document.customerjob
		Forall vi In v
			h$= Strtoken(vi, " | ", 1)
			If JobNumber$<>"" Then JobNumber$= JobNumber$ + ";" ' 
			JobNumber$= JobNumber$ + Strtoken(h$, ":", 2)
		End Forall  		
		
		'JobNumber$ = Trim(Strrightback(Strleftback(source.Document.customerjob(0),"|"),":"))
		If Instr(source.Document.subject(0),"" & JobNumber$ & "") = 0 Then
			Call source.FieldAppendText("Subject"," [" & JobNumber$ & "]")
		Else
			If Instr(source.Document.subject(0),"[") = 1 Then
			Else
				blankjn = Replace(source.Document.subject(0),JobNumber$,"")
				Call source.FieldSetText("Subject",blankjn & " [" & JobNumber$ & "]")
			End If
		End If

Open in new window

0
 
Bill-HansonCommented:
I think I understand what you are trying to accomplish.  In a nutshell, it sounds like you want to generate a new subject that contains the new job numbers while retaining the original subject.  In addition, you want to add the "RE: " prefix to the subject if it does not already contain it.

So, the format for your new subject will always be...

"RE: ORIG_SUBECT [JOB_NUMBER1;JOB_NUMBER2;JOB_NUMBER3;...]"

... where ORIG_SUBECT is the original subject of the email, and JOB_NUMBER(X) are the new job numbers separated by semicolons.

It also sounds like the old subjects are received with or without old job numbers and with or without the "RE: " prefix.  So, the incoming formats could look like any of these...

"ORIG_SUBECT"
"ORIG_SUBECT [JOB_NUMBER1]"
"ORIG_SUBECT [JOB_NUMBER1;JOB_NUMBER2;JOB_NUMBER3;...]"
"RE: ORIG_SUBECT"
"RE: ORIG_SUBECT [JOB_NUMBER1]"
"RE: ORIG_SUBECT [JOB_NUMBER1;JOB_NUMBER2;JOB_NUMBER3;...]"

If this is not correct, please let me know.

Assuming that my understanding is correct, you need a way to identify the JOB_NUMBER part and remove it from the subject so that you are only left with the original subject (and perhaps a leading "RE: ").  This is where the 'Like' operator will help.

(First, I would abandon the idea of using a field translation formula for this, and concentrate on getting it to work in QuerySave.  Having all the code in one place will make things easier to read and maintain.)

The 'Like' operator can match specific patterns within a string.  In your case, we need to match a string that looks like this ("[DLG-G0001;DLG-G0003;DLG-R2004]").  Your success in this is dependent upon how unique your job number format is.  For example, if your job numbers always start with "DLG-" then our pattern matching can be excellent.  If not, then it will still be very good, but could falsely match a subject that looks like this: "Buy Now!!! [spam]".  The bottom line is this:  if there is a dependable pattern in your job number format, our matching code will work better.  Just looking at your job numbers, it looks like another dependable pattern might be "XXX-NAAAA" where 'XXX' is the prefix (DLG), '-' is a literal dash, 'N' is always numeric, and 'AAAA' is always alpha.  If this is true, then our pattern matching code will be more complex, but also more reliable.

OK, enough background.  The 1st code example below shows an example agent that I used to test subjects using only the fact the job number part will always be enclosed in square brackets and will always be at the end of the subject.  For this, I used the pattern "* [[]*[]]".  This means "match any number of characters, followed by a space, followed by an open square bracket, followed by any number of characters, followed by a close square bracket, end of string".  If your job numbers always start with "DLG-", I would have used "* [[DLG-]*[]]" instead for increased reliability.  If the pattern gets much more complex than this (like in the "XXX-NAAAA" example above) the code will require multiple calls using the Like operator in a loop.  This is a more advanced technique, so I won't confuse this post with an explanation.  If you need this feature, let me know.  The rest of the code is commented and should be self explanatory.  If not, just ask.

The second code example is an attempt to plug my code into yours.
EXAMPLE 1:
 
Sub Initialize
	
	' get the original subject
	Dim subject As String
	subject = "RE: Blahh [DLG-G0001;DLG-G0003;DLG-R2004]"
	If (subject Like "* [[]*[]]") Then
		subject = Strleftback(subject, "[")
	Else
		subject = subject
	End If
	
	' add "RE: " prefix if missing
	If (Left(Lcase(subject), 4) <> "re: ") Then subject = "RE: " & subject
	
	' add the new job number(s)
	Dim jobNumber As String
	jobNumber = "[DLG-G0001]"
	subject = subject & " " & jobNumber
	
	Msgbox subject
	
End Sub
 
 
EXAMPLE 2:
 
Sub Querysend(Source As Notesuidocument, Continue As Variant)
 
        'Check preference and Warn if subject is blank for a new memo
        If source.Document.EnableBlankSubject(0) <> "1" Then
                If source.document.Subject(0) = "" Then
                        If Messagebox(warnTxt, MB_YESNO + MB_ICONQUESTION, warnTitle ) = IDNO Then 
                                vSubjectBlankSend = False
                                Source.GoToField("Subject")
                                Call source.Refresh
                                Call cMemoObject.SetActionInProgress(MEMO_ACTION_NONE)
                                Call Source.Document.ReplaceItemValue("SaveOptions","0")
                                cMemoObject. SendBlankSubject=False
                                continue = False                
                                Exit Sub
                        Else
                                vSubjectBlankSend = True
                                cMemoObject. SendBlankSubject=True
                        End If
                End If
        End If
        
        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),"-"))
                
                ' build new job number
                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
                
								' get the original subject
								Dim subject As String
								subject = Source.Document.Subject(0)
								If (subject Like "* [[]*[]]") Then
									subject = Strleftback(subject, "[")
								Else
									subject = subject
								End If
                
								' add "RE: " prefix if missing
								If (Left(Lcase(subject), 4) <> "re: ") Then subject = "RE: " & subject
								
								' add the new job number(s) and update source doc
								subject = subject & " " & JobNumber$
								Source.Document.Subject = subject
 
                If Instr(source.Document.EnterBlindCopyTo(0),"jobcorrespondence@dalinalaw.com]") = 0 Then
                        Call source.FieldAppendText("EnterBlindCopyTo",",JobCorrespondence@dalinalaw.com")
                End If
                Call Source.FieldSetText("Customer",CustomerName$)
        End If
        
End Sub

Open in new window

0
 
padillrrProject CoordinatorAuthor Commented:
Hey Bill, That's VERY close to what I am trying to do....and now after going through it in my head I think it might be better to clean out the subject line on the query open. That way the new reply will have NO job references on the subject line. I am grabbing the job numbers and populating the picklist so the user can the select more or less job numbers. The job numbers do change considerable so just deleteing the brackets and everything inside the brackets would work, Can this be done on the Queryopen?!?!? or Post Open?!?! I think it would be less confsing for the sender.
0
 
padillrrProject CoordinatorAuthor Commented:
Tried using your code but it's not working and I am assuming that it's because of the format of the job references, I've included the entire code so you can take a look at it. What I've noticed is that if the sender adds any text to the subject line after the job numbers it does not run. Can we just delete the job refernces at the opening of the email so that they don't appear on the subject line? That would be the easiet way plus I could use that code on the forwarding as well.....
Sub Querysend(Source As Notesuidocument, Continue As Variant)
	Dim s As New notesSession 
	Dim ws As New notesUIWorkspace 
	Dim uiview As notesUIView 
	Dim db As notesDatabase 
	Dim dc As notesDocumentCollection 
	Dim doc As notesDocument 
	Dim body As String 
	Dim memo As notesDocument 
	Dim n As Integer 
	Dim newdoc As notesDocument 
	Dim newi As notesItem 
	Dim i As notesItem 
	Dim count As Integer 
	Dim agent As notesAgent 
	Dim memobody As notesRichTextItem 
	Dim docbody As notesRichTextItem 
	Dim docitem As notesItem 
	Dim blankjn As Variant
	Dim response As Variant
	Dim uidoc As NotesUIDocument
	Dim jobcorDB As NotesDatabase
	Dim askme As Integer
	
	Set db = s.CurrentDatabase 
	If source.Document.CustomerJob(0) = "To file please select a job here" Then
	Else	
		Set doc = source.Document
		Set jobcorDB = New notesdatabase("domino1/dalinalaw","jobcor2.nsf")
		'Messagebox "Modify Subject"
		
		Dim subject As String
		subject = Source.Document.Subject(0)
		If (subject Like "* [[]*[]]") Then
			subject = Strleftback(subject, "[")
		Else
			subject = subject
		End If
		
		CustomerName$ = Trim(Strleft(source.Document.customerjob(0),"-"))
		v= source.Document.customerjob
		Forall vi In v
			h$= Strtoken(vi, " | ", 1)
			If JobNumber$<>"" Then JobNumber$= JobNumber$ + ";" ' 
			JobNumber$= JobNumber$ + Strtoken(h$, ":", 2)
		End Forall  		
		
		'JobNumber$ = Trim(Strrightback(Strleftback(source.Document.customerjob(0),"|"),":"))
		If Instr(source.Document.subject(0),"" & JobNumber$ & "") = 0 Then
			Call source.FieldAppendText("Subject"," [" & JobNumber$ & "]")
		Else
			If Instr(source.Document.subject(0),"[") = 1 Then
			Else
				blankjn = Replace(source.Document.subject(0),JobNumber$,"")
				Call source.FieldSetText("Subject",blankjn & " [" & JobNumber$ & "]")
			End If
		End If
		Call Source.FieldSetText("Customer",CustomerName$)
		Set memo = New NotesDocument(jobcordb)
		Call doc.CopyAllItems(memo,True)
		Call memo.ReplaceItemValue("Company",CustomerName$)
		If doc.Principal(0) = "" Then
			SentBy = doc.from
		Else
			SentBy = doc.Principal
		End If
		SentTo = doc.SendTo
		Copiedto = doc.CopyTo
		Recipients = Arrayappend(SentTo,CopiedTo)
		recipients = Arrayappend(Recipients,SentBy)
		Forall c In Recipients
			If Instr(c,"dalinalaw") = 0 Then
				mailsort$ = "Client"
				Goto finish
			Else
				mailsort$ = "Internal"
			End If
		End Forall
finish:
		memo.mailsort = mailsort$
		Call doc.ReplaceItemValue("Filed","Yes")
		Call memo.RemoveItem("$REF")
		Call doc.Save(True,False)
		Call memo.save(True,False)	
	End If
End Sub

Open in new window

0
 
Bill-HansonCommented:
>> "Can we just delete the job references at the opening of the email so that they don't appear on the subject line?"

Sure.  I would probably place the code in PostOpen.

>> "What I've noticed is that if the sender adds any text to the subject line after the job numbers it does not run."

You can test for this too.  To allow for characters after the job references you would add an asterisk to the end of the pattern like this: "* [[]*[]]*".
0
 
padillrrProject CoordinatorAuthor Commented:
so you mean add this to the post open?
Dim subject As String
            subject = Source.Document.Subject(0)
            If (subject Like "* [[]*[]]") Then
                  subject = Strleftback(subject, "[")
            Else
                  subject = subject
0
 
Bill-HansonCommented:
Sure, that should work.

Also, if you want to match subjects that have characters after the job references, you'll need to use this pattern: "* [[]*[]]*"
0
 
Bill-HansonCommented:
Oops!  I just noticed that you did not update the document with the new subject.  Also, this will not work unless the document is in edit mode, so you either need to force edit mode in PostOpen or check that the form is in edit mode before updating the document.  Here's an example that will force the form into edit mode.

Also, the line that reads "subject = subject" is redundant.  I just left it there in case you wanted to do something with subjects that did not match.  It has been removed from this example.
Sub Postopen(Source As Notesuidocument)
	Dim subject As String
	Source.EditMode = True
	subject = Source.Document.Subject(0)
	If (subject Like "* [[]*[]]") Then subject = Strleftback(subject, "[")
	Source.Document.Subject = subject
End Sub

Open in new window

0
 
padillrrProject CoordinatorAuthor Commented:
tried that but it didn't work, so I did this:
Subject$ = Trim(Strleft(source.Document.Subject(0),"["))
      Call Source.FieldSetText("Subject",Subject$)
 which works but now I get an error when I just want to open the email, I'm also having a the problem that when the email is mailed into the mail in database the subject line is again blanked out.....any ideas?
0
 
Bill-HansonCommented:
Did you see my most recent post?
0
 
padillrrProject CoordinatorAuthor Commented:
I did I think the (subject Like "* [[]*[]]") is not working, the job numbers look like this:
Re: TEST REF NUMBER [DLG-G0003;DLG-R2004]
but that can easlily be [999-9999;DL1-AS19;123-ASFD;XXX-9999]
If you look at the code I am making a copy of the email onto another db jobcor, which is a mail in db when the code runs it is blanking out the subject line on the jobcor app.
0
 
Bill-HansonCommented:
The pattern "* [[]*[]]" will only match subjects that have at least one space before the job numbers.  Since this is not the case, you need to change to pattern to "*[[]*[]]" so that text before the job numbers is not required.

Take a few minutes and read the help article for the Like operator.  It is fairly straight forward.
0
 
padillrrProject CoordinatorAuthor Commented:
Bill I did a read on the LIKE operator and fully understand it but regardless of what combination I use it is not working on the POSTOPEN. Whne I click on the reply, the subject line still contain the job numbers. using the: Subject$ = Trim(Strleft(source.Document.Subject(0),"["))
      Call Source.FieldSetText("Subject",Subject$)
seems to work I get a nice subject line with the previous subject minus the jobnumbers. when I do the send the subject is then populated by the new jobnumber which is basically what I need but when the email goes to the jobcor app the subject line is blanked out again?!?!?! Is the postopen running again?!?! Seems like the form is refreshing before it is copied and therefore running the postopen again. If you can figure this out for me I'll be buying you beers for a while! I've been working on this for qbout a weeks. I can get one thing to work then something else won't about to lose my contract over this!
0
 
Bill-HansonCommented:
It's hard for me to analyze this since I don't have the full picture of what your application does.  You're asking me to troubleshoot both ends of an application with very little knowledge of either end.

From your posts so far, it sounds like you get an email into DB1.  Then, you change the subject of the email in DB1 before sending it to DB2.  Then, for some reason, the subject is missing in DB2.  To be honest, there could be any number of reasons that the subject is wrong.

Personally, I never use the QuerySend method.  Instead, I prefer to control the entire process rather than letting Notes try to handle it automatically.  For example, If I want to send an email based on the contents of the current email, I will write a function that looks something like the following example.  This way, I'm not really sending the current document, but rather a copy of the current document.


Sub Click(Source As Button)
	
	Dim sess As New NotesSession
	Dim ws As New NotesUIWorkspace
	Dim uidoc As NotesUIDocument
	Dim memo As NotesDocument
	Set uidoc = ws.CurrentDocument
	Set memo = sess.CurrentDatabase.CreateDocument
	Call uidoc.Document.CopyAllItems(memo)
	If (Instr(memo.Subject(0), "[") <> 0) Then
		memo.Subject = Strleftback(memo.Subject(0), "[") & " [Job_Numbers]"
	End If
	Call memo.Send(False)
	
End Sub

Open in new window

0
 
padillrrProject CoordinatorAuthor Commented:
Hey Bill,
Theres a lot of things I owuld have done differently, but I came into this project very late in the game and what they want is to get it fixed. I'm actually almost there. Was able to figure out the subject line job number thing when replying so that it is actually clearing out the subject line and replacing it with the new ones.
By the way the process is as follows:
1 Employee creates email sending it internally
  he picks job numbers from a list could be 1 job could be 10,20 etc
2. Sends mail this is a MEMO ( I have a query send here that checks for job numbers is YES then files(emails) it to the JOBCOR (mail in db) app as well as sends it to the recipient. (I also append the the job numbers to the subject line.
3. Recipient (internal only) decides to REPLY,  I clear out the job numbers from the subject line and populate the picklist with the previous jobnumbers
4. The recipient can now eith delete or add new jobnumbers or leave as is enters message and sends.
5. I then append the new jobnumbers to the subject line and make a COPY of the reply on the JOBCOR app.
This is all working fine, what is happening (on replies only) is that on the JOBCOR side the email has no jobnumbers on the subject which then prevents me from categorizing the email. If you look at the code you can see where I am doing the coping and where I send it to the jobcor I can't find where it is DELETING the jobnumers from the subject line?!?!?!
0
 
Bill-HansonCommented:
>> "If you look at the code you can see where I am doing the coping and where I send it to the jobcor I can't find where it is DELETING the jobnumers from the subject line?!?!?!"

I see.  I have to admit that I didn't analyze your original code as well as I should have (got caught up on the pattern matching thing).  Before, I thought that you were modifying then mailing the current document (which I don't like doing).  That's why I described making a copy of the current document, then mailing the copy (or saving it directly to the target db, which is exactly what you are doing).  :)

Anyway, there is one thing in the code from post #22944008 that bothers me.  The mixed use of front-end and back-end methods is confusing and may be causing the subject problems.

For example, you are reading values from the back-end document (line 49), writing to the front-end document (line 50), then copying values from the back-end (line 60).

The code will be cleaner, faster, and more reliable if you stick to one or the other.  Also, since you need to use NotesDocument.CopyAllItems, it will be easier to stick to the back-end methods.  You could also use only front-end methods, then call NotesUIDocument.Save to update the back-end before calling NotesDocument.CopyAllItems, but that is harder and error prone.

Here is the same code from post #22944008 re factored using my own design guidelines (the rules that I impose on those coding for me) such as declaring all variables, removing unused variables, using "Options Declare" to prevent compile-time errors, using 'goto' only for error trapping, organizing code into logical, documented blocks, etc...

Even if this does not do exactly what you want with the subject, it is a good place to start since the code is only operating using backend methods.
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
	
	' 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
	
	' extract subject without job numbers
	subject = Source.Document.Subject(0)
	If (subject Like "* [[]*[]]") Then subject = Strleftback(subject, "[") Else subject = subject
	
	' 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
	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.Company = customerName
	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 Sub

Open in new window

0
 
padillrrProject CoordinatorAuthor Commented:
WOW!!! I'd love to work for you, I know I could learn so much, never really had a mentor, just picked it up on my own. The code is so close.....
IF the sender writes anything on the subject line after the job numbers they are not deleted and the new job number is appended to the end of the subject.
The email sent out is not parsing the subject line at all so the subject line is not picking up the new jobnumbers nor is itrdeleting the old. I'm running the code through the debugger now but can't seem to find where that is happening.
Anyway to get rid of the jobnumbers on the postopen?
I'm trying to make it so that the customerjob field is prepopulated with the previous job numbers to that they can either choose to keep those job numbers or change them on the reply......
I do appreciate all your help on this.
0
 
padillrrProject CoordinatorAuthor Commented:
I've gone over the form with the debugger over and over and can't find why the subject on the email being sent out is not being parsed. It works almost perfectly for the jobcor except is I add anything to the subject line then it just appends the job number but does not delete the old one..... I've tried modifying the LIKE operator but can't get it to leave anything alone after the jobnumbers, this needs to happen for the email being sent out as well......
0
 
Bill-HansonCommented:
Here's my stab at a PostOpen method that will extract the old job numbers from the subject and store them in a back-end field named "OldJobNumbers".  This should give you a trimmed subject with no job numbers and the old job numbers are saved in a hidden field.  Then, you can simply use the hidden OldJobNumbers field as the choices in your select field.  Since we are generating the choices in PostOpen, you need to ensure that the select field's "Refresh choices on document refresh" property is enabled.

(Keep in mind that since users are allowed to modify the subject, there is no fool-proof solution for parsing the job numbers out of the subject.)
Sub Postopen(Source As Notesuidocument)
	Dim doc as NotesDocument
	Dim subject As String
	Dim oldJobNumbers As Variant
	Source.EditMode = True
	Set doc = Source.Document
	subject = doc.GetItemValue("Subject")(0)
	If (subject Like "*[[]*[]]*") Then
		oldJobNumbers = Split(Strleftback(Strrightback(subject, "["), "]"), ";")
		subject = Trim(Strleftback(subject, "["))
	End If
	doc.Subject = subject
	doc.OldJobNumbers = oldJobNumbers
	Call Source.Refresh
End Sub

Open in new window

0
 
Bill-HansonCommented:
>> "I've tried modifying the LIKE operator but can't get it to leave anything alone after the jobnumbers"

The code I just posted does not leave anything after the numbers either!  This one does.
Sub Postopen(Source As Notesuidocument)
	Dim doc as NotesDocument
	Dim subject As String, postText As String
	Dim oldJobNumbers As Variant
	Source.EditMode = True
	Set doc = Source.Document
	subject = doc.GetItemValue("Subject")(0)
	If (subject Like "*[[]*[]]*") Then
		oldJobNumbers = Split(Strleftback(Strrightback(subject, "["), "]"), ";")
		postText = Trim(Strrightback(subject, "]"))
		subject = Trim(Strleftback(subject, "["))
	End If
	doc.Subject = Trim(subject + " " + postText)
	doc.OldJobNumbers = oldJobNumbers
	Call Source.Refresh
End Sub

Open in new window

0
 
padillrrProject CoordinatorAuthor Commented:
Hey Bill, This is what I've done, I added these lines to the postopen:
Subject$ = Trim(Strleft(source.Document.Subject(0),"["))
      Call Source.FieldSetText("Subject",Subject$)
commented out these lines in your code on the querysend:
' extract subject without job numbers
      'subject = Source.Document.Subject(0)
      'If (subject Like "* [[]*[]]") Then subject = Strleftback(subject, "[") Else subject = subject and added this to the querysend:
Call source.FieldAppendText("Subject"," [" & JobNumber$ & "]")
THe only issue now is that on the JOBCOR db the subject only contains the jobnumber the rest of the subject is deleted the subject on the email is fine...
The customerjob field is not populated. I've tried using this on the reply button:
dCJob := dsp_CustomerJob;
@UpdateFormulaContext;
FIELD CustomerJob:=dCJob;
but it isn't working........
0
 
Bill-HansonCommented:
I don't know what else to tell you.  I've recommended NOT using front-end classes to update the subject, but you continue to do so.  That is probably why your not getting the right subject.
0
 
padillrrProject CoordinatorAuthor Commented:
I've tried using your code and it isn't working. The subject line keeps the old job numbers. I run it through the debugger and can't see why that's happening. It works fine on the copy to jobcor but the email sent out subject line is not parsed properly. When the email is replied to the subject line contains the old job numbers is I add anything after those job numbers on the subject line then it just appends the new job number after what I wrote. I apologize if I'm being a little backwards......
0
 
Bill-HansonCommented:
Sorry, I'm not sure what to tell you from here.  Maybe it would be best to start with a fresh, blank form and add one thing at a time until you find the problem.  I would start with PostOpen.  Once that works, focus on the copy to jobcor.
0
 
padillrrProject CoordinatorAuthor Commented:
I think I'll do that....Just as a headsup, when I run your code through the debugger it does trim the subject line but when the reply opens it still shows the jobnumber on the subject line. The code works I just can't understand why it isn't displaying on the form that way?!?!
0
 
Bill-HansonCommented:
>> "reply opens it still shows the jobnumber on the subject line"

How are you composing the reply?  I haven't seen that code yet.

BTW, is this being done in a standard email template?  I remember seeing a reference to cMemoObject in your original post.
0
 
padillrrProject CoordinatorAuthor Commented:
Yes this is on a standard mail template and I am using the Reply button on the template. This will eventually have to work for all replies and forwarding i.e with attachments without reply to all etc etc. Normally I wouldn't touch the standard template but this is a legacy system and it's what the client wants. I have suggested other ways but it is what they want......
0
 
Bill-HansonCommented:
>> "Yes this is on a standard mail template and I am using the Reply button on the template."

OK, that explains a lot.  That button composes a new Reply document that inherits values from the selected document.  The values that are inherited are always taken from disk, not the current form.  That means that any changes that are not saved to disk will not be present in the reply.  That is why the email template hides the Reply buttons whenever a delivered memo is placed in edit mode -- so that users won't become confused if they change something then reply.  The way to handle this is to always save the current document before composing a reply if you have made changes to any field.

>> "I have suggested other ways but it is what they want......"

Bummer!  I feel your pain.
0
 
padillrrProject CoordinatorAuthor Commented:
Thanks Bill I finally figured it out, it was all in the mail in db, replies are considered responses it was checked to not see responses in the view once I unchecked it, it worked fine Thanks
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 19
  • 15
Tackle projects and never again get stuck behind a technical roadblock.
Join Now