Ray Padilla
asked on
Need to modify lotus script to parse more then one entry
The following code is parsing job numbers from a string, I've now made it so that there are more then one job number separated by " ; " how do I get all the job numbers and copy then to the subject line separated by brackets [ ] I am also running into the issue that when I reply to these emails I get additional brackets without the job numbers...this is HOT! Below is the format of what needs to be parsed, I need all the client numbers between the - and the |
ClientName, xxx -1192:1192-G0001 | JobName; ClientName2, xxx2 - 1085:1085-P0001 | jobname; ClientName3, xxx3 - 1085:1085-P0002 | jobname
ClientName, xxx -1192:1192-G0001 | JobName; ClientName2, xxx2 - 1085:1085-P0001 | jobname; ClientName3, xxx3 - 1085:1085-P0002 | jobname
Query Send Code:
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),"-"))
JobNumber$ = Trim(Strrightback(Strleftback(source.Document.customerjob(0),"|"),":"))
If Instr(source.Document.subject(0)," [" & JobNumber$ & "]") = 0 Then
Call source.FieldAppendText("Subject"," [" & JobNumber$ & "]")
End If
If Instr(source.Document.EnterCopyTo(0),"jobcorrespondence@dalinalaw.com]") = 0 Then
Call source.FieldAppendText("EnterCopyTo",",JobCorrespondence@dalinalaw.com")
End If
Call Source.FieldSetText("Customer",CustomerName$)
End If
End Sub
ASKER
Sorry working with legacy applications. Any way to look for all the colons and grab the numbers from the colon to the | ???
There's another function that might help you out here: StrToken
StrToken(expression as STRING, delimiter as STRING, wordNumber as LONG, compMethod as INTEGER) as STRING
See the Designer Help Database.
StrToken(expression as STRING, delimiter as STRING, wordNumber as LONG, compMethod as INTEGER) as STRING
See the Designer Help Database.
ASKER
Sounds like I can use that but how do I get it to pick up all the job numbers before the | and after the :
Come on, I know you can do this yourself!
s = "ClientName, xxx -1192:1192-G0001 | JobName; ClientName2, xxx2 - 1085:1085-P0001 | jobname; ClientName3, xxx3 - 1085:1085-P0002 | jobname"
v= Split(s, ";") ' will explode s on the semicolons
Forall vi In v
w= StrToken(StrToken(vi, " | ", 1), " - ", 2)
' w is the word you're looking for!
Print w
End Forall
s = "ClientName, xxx -1192:1192-G0001 | JobName; ClientName2, xxx2 - 1085:1085-P0001 | jobname; ClientName3, xxx3 - 1085:1085-P0002 | jobname"
v= Split(s, ";") ' will explode s on the semicolons
Forall vi In v
w= StrToken(StrToken(vi, " | ", 1), " - ", 2)
' w is the word you're looking for!
Print w
End Forall
ASKER
Help This isn't working...
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"
v= Split(source.Document.customerjob(0), ";")
Forall vi In v
JobNumber$= Strtoken(Strtoken(vi, " | ", 1), " - ", 2)
If Instr(source.Document.subject(0)," [" & JobNumber$ & "]") = 0 Then
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 Forall
End If
End Sub
I'll look into this tomorrow. In the meantime, you could check with the debugger. To make debugging easier, use the following code:
v= Split(source.Document.cust omerjob(0) , ";")
Forall vi In v
h$= Strtoken(vi, " | ", 1)
JobNumber$= Strtoken(h$, " - ", 2)
If Instr(source.Document.subj ect(0)," [" & JobNumber$ & "]") = 0 Then
Call source.FieldAppendText("Su bject"," [" & JobNumber$ & "]")
End If
If Instr(source.Document.Ente rBlindCopy To(0),"job correspond ence@dalin alaw.com]" ) = 0 Then
Call source.FieldAppendText("En terBlindCo pyTo",",Jo bCorrespon dence@dali nalaw.com" )
End If
Call Source.FieldSetText("Custo mer",Custo merName$)
End Forall
v= Split(source.Document.cust
Forall vi In v
h$= Strtoken(vi, " | ", 1)
JobNumber$= Strtoken(h$, " - ", 2)
If Instr(source.Document.subj
Call source.FieldAppendText("Su
End If
If Instr(source.Document.Ente
Call source.FieldAppendText("En
End If
Call Source.FieldSetText("Custo
End Forall
ASKER
Got a little Closer but no cigar yet, I am still only grabbing the 1st job number, I've posted the code with a change to this line: JobNumber$= Strtoken(h$, ":", 2) cahnged it from - to : and now I can get the job number only, but I am looking to grab all the job jumbers and append then to the Subject.
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"
v= Split(source.Document.customerjob(0), ";")
Forall vi In v
h$= Strtoken(vi, " | ", 1)
JobNumber$= Strtoken(h$, ":", 2)
If Instr(source.Document.subject(0)," [" & JobNumber$ & "]") = 0 Then
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 Forall
End If
End Sub
You've got your logic wrong...
v= Split(source.Document.cust omerjob(0) , ";")
JobNumber$= ""
Forall vi In v
h$= Strtoken(vi, " | ", 1)
If JobNumber$<>"" Then JobNumber$= JobNumber$ + "|" ' separator ??
JobNumber$= JobNumber$ + Strtoken(h$, ":", 2)
End Forall
If Instr(source.Document.subj ect(0)," [" & JobNumber$ & "]") = 0 Then
Call source.FieldAppendText("Su bject"," [" & JobNumber$ & "]")
End If
If Instr(source.Document.Ente rBlindCopy To(0),"job correspond ence@dalin alaw.com]" ) = 0 Then
Call source.FieldAppendText("En terBlindCo pyTo",",Jo bCorrespon dence@dali nalaw.com" )
End If
Call Source.FieldSetText("Custo mer",Custo merName$)
First you have to collect all jobnumbers, and only then you can use the result in your form.
v= Split(source.Document.cust
JobNumber$= ""
Forall vi In v
h$= Strtoken(vi, " | ", 1)
If JobNumber$<>"" Then JobNumber$= JobNumber$ + "|" ' separator ??
JobNumber$= JobNumber$ + Strtoken(h$, ":", 2)
End Forall
If Instr(source.Document.subj
Call source.FieldAppendText("Su
End If
If Instr(source.Document.Ente
Call source.FieldAppendText("En
End If
Call Source.FieldSetText("Custo
First you have to collect all jobnumbers, and only then you can use the result in your form.
ASKER
Still only getting the 1st job number on the subject line....
Use the Debugger and step through your code!!
ASKER
Ran it through the debugger several times, the code seems to be working except for when it splits the customerjob it only displays the 1st object, I can change the code: v= Split(source.Document.cust omerjob(0) , ";") by changing the number I can grab the different job numbers but it won't return all the job numbers...I've looked at split on the designer help and can't find whats missing.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Great Job Sjef, Thanks I've attached the final code that worked....
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"
'v= Split(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$)
End If
End Sub
ASKER
You not only help but you teach, thanks! I've learned a lot from you through the years!
Brilliant! Thanks for the compliment :-)
Suppose your string is in the variable s
1) Use the Split() function
v= Split(s, ";") ' will explode s on the semicolons
2) loop through individual items in v
Forall vi In v
w= Split(vi, "|")
etc.
But, er, why is the string so complex, isn't it possible to have an easier string?