pucktarget2
asked on
Looping help
Can anyone point me in the right direction, I am fairly new to Lotus Script.
I am pulling fields through an ODBC connection into a database to fill a form. I built the following code to do that. This is in the postopen event of a form in the notes database and works great at pulling the first record and populating the appropriate fields.
Sub Postopen(Source As Notesuidocument)
Dim uidoc As NotesUIDOcument
Dim note As NotesDocument
Dim Con As New ODBCConnection
Dim qry As New ODBCQuery
Dim result As New ODBCResultSet
Set qry.Connection=con
Set result.query=qry
con.ConnectTo("OARFAutomat ion")
qry.SQL= "SELECT tblMasterOARFControl.BANK, " _
& "tblMasterOARFControl.OBLI GOR, tblMasterOARFControl.OBLIG ATION, " _
& "tblMasterOARFControl.CUST NAME, tblMasterOARFControl.COLLT YPE, " _
& "tblMasterOARFControl.MATD ATE, tblMasterOARFControl.ITEM, " _
& "tblMasterOARFControl.Firs tOfCOLLDES C1, tblMasterOARFControl.First OfCOLLDESC 2," _
& "tblMasterOARFControl.OFFC RCODE, tblMasterOARFControl.PREPA Y, " _
& "tblMasterOARFControl.txt_ EMAILADD, tblMasterOARFControl.txtGo odtoSend, " _
& "tblMasterOARFControl.txtO rigSendDat e " _
& "FROM tblMasterOARFControl WHERE (((tblMasterOARFControl.tx tGoodtoSen d)=-1));"
result.execute
If result.IsResultSetAvailabl e Then
Dim ws As New NotesUIWOrkspace
Dim Obligor As String
Dim Obligation As String
Dim Item As String
Set uidoc = ws.CurrentDocument
Set note = uidoc.Document
result.FirstRow
Set doc = ws.CurrentDocument.Documen t
Call Source.FieldSetText("txtBa nkNum",res ult.GetVal ue("BANK") )
Call Source.FieldSetText("txtOb ligor",res ult.GetVal ue("OBLIGO R"))
Call Source.FieldSetText("txtOb ligation", result.Get Value("OBL IGATION"))
Call Source.FieldSetText("txtCu stomerName ",result.G etValue("C USTNAME"))
Call Source.FieldSetText("txtCo llateralTy pe",result .GetValue( "COLLTYPE" ))
Call Source.FieldSetText("txtIt emNum",Str (result.Ge tValue("IT EM")))
Call Source.FieldSetText("txtCo llDesc1",r esult.GetV alue("Firs tofCOLLDES C1"))
Call Source.FieldSetText("txtCo llDesc2",r esult.GetV alue("Firs tofCOLLDES C2"))
Call Source.FieldSetText("SendT o",result. GetValue(" txt_EMAILA DD"))
'doc.Save(True)
End If
End Sub
Now the fun part, I need it to move to the next row and evaluate the Obligor, Obligation fields on the info that was pulled in. If the two are equal, I need to to evaluate the Item field, if it is the same, skip the record. If it is different, then scrape the new item #, new colldesc1 and colldesc2 into those fields (which are built to allow multiple values). If the Obligor is different, it will close and send the doc to the addressee (which is scraped in). Then I need to to open another doc and start all over.
I tried to use Lotus Help and a couple of web sites, but I could not find any code that would help. Thanks all!!
I am pulling fields through an ODBC connection into a database to fill a form. I built the following code to do that. This is in the postopen event of a form in the notes database and works great at pulling the first record and populating the appropriate fields.
Sub Postopen(Source As Notesuidocument)
Dim uidoc As NotesUIDOcument
Dim note As NotesDocument
Dim Con As New ODBCConnection
Dim qry As New ODBCQuery
Dim result As New ODBCResultSet
Set qry.Connection=con
Set result.query=qry
con.ConnectTo("OARFAutomat
qry.SQL= "SELECT tblMasterOARFControl.BANK,
& "tblMasterOARFControl.OBLI
& "tblMasterOARFControl.CUST
& "tblMasterOARFControl.MATD
& "tblMasterOARFControl.Firs
& "tblMasterOARFControl.OFFC
& "tblMasterOARFControl.txt_
& "tblMasterOARFControl.txtO
& "FROM tblMasterOARFControl WHERE (((tblMasterOARFControl.tx
result.execute
If result.IsResultSetAvailabl
Dim ws As New NotesUIWOrkspace
Dim Obligor As String
Dim Obligation As String
Dim Item As String
Set uidoc = ws.CurrentDocument
Set note = uidoc.Document
result.FirstRow
Set doc = ws.CurrentDocument.Documen
Call Source.FieldSetText("txtBa
Call Source.FieldSetText("txtOb
Call Source.FieldSetText("txtOb
Call Source.FieldSetText("txtCu
Call Source.FieldSetText("txtCo
Call Source.FieldSetText("txtIt
Call Source.FieldSetText("txtCo
Call Source.FieldSetText("txtCo
Call Source.FieldSetText("SendT
'doc.Save(True)
End If
End Sub
Now the fun part, I need it to move to the next row and evaluate the Obligor, Obligation fields on the info that was pulled in. If the two are equal, I need to to evaluate the Item field, if it is the same, skip the record. If it is different, then scrape the new item #, new colldesc1 and colldesc2 into those fields (which are built to allow multiple values). If the Obligor is different, it will close and send the doc to the addressee (which is scraped in). Then I need to to open another doc and start all over.
I tried to use Lotus Help and a couple of web sites, but I could not find any code that would help. Thanks all!!
Forgot to tell you where the I part of the script goes
You have to replace these lines with I part
Call Source.FieldSetText("txtIt emNum",Str (result.Ge tValue("IT EM")))
Call Source.FieldSetText("txtCo llDesc1",r esult.GetV alue("Firs tofCOLLDES C1"))
Call Source.FieldSetText("txtCo llDesc2",r esult.GetV alue("Firs tofCOLLDES C2"))
II part will come after last end if statement
Hope I was clear
You have to replace these lines with I part
Call Source.FieldSetText("txtIt
Call Source.FieldSetText("txtCo
Call Source.FieldSetText("txtCo
II part will come after last end if statement
Hope I was clear
ASKER
So this code:
obligor = result.GetValue("OBLIGOR")
obligation = result.GetValue("OBLIGATIO N")
If obligor != obligation then
' Evaluate item
else
' New Item#, new colldesc1, colldesc2 inserted
set item = doc.getFirstItem("txtItemN um")
set colldesc1 = doc.getFirstItem("txtcolld esc1")
set colldesc2 = doc.getFirstItem("txtcolld esc2")
call item.appendTOTextList( Str(result.GetValue("ITEM" )) )
call colldesc1.appendTOTextList ( result.GetValue("FirstofCO LLDESC1"))
call colldesc2.appendTOTextList ( result.GetValue("FirstofCO LLDESC2"))
SendDoc = True
End If
Takes the place of this already existing code:
Call Source.FieldSetText("txtIt emNum",Str (result.Ge tValue("IT EM")))
Call Source.FieldSetText("txtCo llDesc1",r esult.GetV alue("Firs tofCOLLDES C1"))
Call Source.FieldSetText("txtCo llDesc2",r esult.GetV alue("Firs tofCOLLDES C2"))
And the last part goes after the last end if. Is that correct?? Thanks for the help again. I tried Lotus Help to build it myself but the examples were too vague.
Puck
obligor = result.GetValue("OBLIGOR")
obligation = result.GetValue("OBLIGATIO
If obligor != obligation then
' Evaluate item
else
' New Item#, new colldesc1, colldesc2 inserted
set item = doc.getFirstItem("txtItemN
set colldesc1 = doc.getFirstItem("txtcolld
set colldesc2 = doc.getFirstItem("txtcolld
call item.appendTOTextList( Str(result.GetValue("ITEM"
call colldesc1.appendTOTextList
call colldesc2.appendTOTextList
SendDoc = True
End If
Takes the place of this already existing code:
Call Source.FieldSetText("txtIt
Call Source.FieldSetText("txtCo
Call Source.FieldSetText("txtCo
And the last part goes after the last end if. Is that correct?? Thanks for the help again. I tried Lotus Help to build it myself but the examples were too vague.
Puck
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hey Hamanth, Here is what I have so far. But I am getting a error message on the highlighted item below. The debugger gives a "Not an instance name error message.
Do
Call Source.FieldSetText("txtBa nkNum",res ult.GetVal ue("BANK") )
Call Source.FieldSetText("txtRM ",result.G etValue("O FFCRCODE") )
Call Source.FieldSetText("txtPr epayCode", result.Get Value("PRE PAY"))
Call Source.FieldSetText("txtCu stomerName ",result.G etValue("C USTNAME"))
Call Source.FieldSetText("txtCo llateralTy pe",result .GetValue( "COLLTYPE" ))
Call Source.FieldSetText("txtOb ligor",res ult.GetVal ue("OBLIGO R"))
Call Source.FieldSetText("txtOb ligation", result.Get Value("OBL IGATION"))
Call Source.FieldSetText("SendT o",result. GetValue(" txt_EMAILA DD"))
obligor = result.GetValue("OBLIGOR")
obligation = result.GetValue("OBLIGATIO N")
If obligor = obligation Then
' Evaluate item
Else
' New Item#, new colldesc1, colldesc2 inserted
Set item = doc.getFirstItem("txtItemN um")
Set colldesc1 = doc.getFirstItem("txtcolld esc1")
Set colldesc2 = doc.getFirstItem("txtcolld esc2")
Call item.appendTOTextList(Str( result.Get Value("ITE M")))
Call colldesc1.appendTOTextList ( result.GetValue("FirstofCO LLDESC1"))
Call colldesc2.appendTOTextList ( result.GetValue("FirstofCO LLDESC2"))
SendDoc = True
End If
result.nextrow
Loop
End If
' Insert this at the end of the sub i.e after resulset endif
If SendDoc Then
Recipients = "Recipient Name"
Call doc.Send( True, Recipients)
End If
Thanks!!
Do
Call Source.FieldSetText("txtBa
Call Source.FieldSetText("txtRM
Call Source.FieldSetText("txtPr
Call Source.FieldSetText("txtCu
Call Source.FieldSetText("txtCo
Call Source.FieldSetText("txtOb
Call Source.FieldSetText("txtOb
Call Source.FieldSetText("SendT
obligor = result.GetValue("OBLIGOR")
obligation = result.GetValue("OBLIGATIO
If obligor = obligation Then
' Evaluate item
Else
' New Item#, new colldesc1, colldesc2 inserted
Set item = doc.getFirstItem("txtItemN
Set colldesc1 = doc.getFirstItem("txtcolld
Set colldesc2 = doc.getFirstItem("txtcolld
Call item.appendTOTextList(Str(
Call colldesc1.appendTOTextList
Call colldesc2.appendTOTextList
SendDoc = True
End If
result.nextrow
Loop
End If
' Insert this at the end of the sub i.e after resulset endif
If SendDoc Then
Recipients = "Recipient Name"
Call doc.Send( True, Recipients)
End If
Thanks!!
ASKER
Would not allow me to highlight: Here is the line of code that is giving me a problem so far:
Call item.appendTOTextList(Str( result.Get Value("ITE M")))
Call item.appendTOTextList(Str(
You have to declare the objects like this on top
Dim item, colldesc1, colldesc2 as NotesItem
Dim item, colldesc1, colldesc2 as NotesItem
ASKER
Shoulda figured that. Doh!
Will this loop through the entire resultset? I did not notice any looping "do" function in the code you gave. Is it not needed in this instance?
puck
Will this loop through the entire resultset? I did not notice any looping "do" function in the code you gave. Is it not needed in this instance?
puck
yes it should be in a do loop, I just provided you a chunk of it.. Sorry I am really out of time. So will respond to you later in detail.
ASKER
Hey Hemanth...I have not forgotten about you. We are short people this week and are in the midst of an upgrade to Windows 2000. I have been assisting with issues caused as a result of the switch. I will be back later this week or early next.
Until then
Puck
Until then
Puck
ASKER
Hey Hemanth. I am back. Finally got through the woods after last week and I have been able to do some more work on my code above. Here is what I have right now. I moved the function out of the post open section of the form and into an agent.
Sub Initialize
Dim s As New notessession
Dim db As NotesDatabase
Dim doc As NotesDocument
Dim Con As New ODBCConnection
Dim qry As New ODBCQuery
Dim result As New ODBCResultSet
Dim item, colldesc1, colldesc2, Obligation, CollType As NotesItem
Set db=s.currentdatabase
Set qry.Connection=con
Set result.query=qry
con.ConnectTo("OARFAutomat ion")
qry.SQL= "SELECT tblMaster.BANK, tblMaster.OBLIGOR, tblMaster.OBLIGATION, tblMaster.CUSTNAME, " _
& "tblMaster.PROCTYPE, tblMaster.COLLTYPE, tblMaster.MATDATE, tblMaster.ITEM, " _
& "tblMaster.FirstOfCOLLDESC 1, tblMaster.FirstOfCOLLDESC2 , tblMaster.OFFCRCODE, " _
& "tblMaster.PREPAY, tblMaster.txt_EMAILADD, tblMaster.txtReadyToSendIn d " _
& "FROM tblMaster " _
& "GROUP BY tblMaster.BANK, tblMaster.OBLIGOR, tblMaster.OBLIGATION, tblMaster.CUSTNAME, " _
& "tblMaster.PROCTYPE, tblMaster.COLLTYPE, tblMaster.MATDATE, tblMaster.ITEM, " _
& "tblMaster.FirstOfCOLLDESC 1, tblMaster.FirstOfCOLLDESC2 , tblMaster.OFFCRCODE, " _
& "tblMaster.PREPAY, tblMaster.txt_EMAILADD, tblMaster.txtReadyToSendIn d " _
& "HAVING (((tblMaster.txtReadyToSen dInd)=-1)) ;"
result.execute
If result.IsResultSetAvailabl e Then
result.FirstRow
Do
Set doc=db.CreateDocument
doc.SendTo=result.GetValue ("txt_EMAI LADD")
doc.txtBankNum=result.GetV alue("BANK ")
doc.txtObligor=result.GetV alue("OBLI GOR")
doc.txtObligation=result.G etValue("O BLIGATION" )
doc.txtCustomerName=result .GetValue( "CUSTNAME" )
doc.txtCollateralType=resu lt.GetValu e("COLLTYP E")
doc.txtNoteDate=result.Get Value("MAT DATE")
doc.txtPrepayCode=result.G etValue("P REPAY")
doc.txtRM=result.GetValue( "OFFCRCODE ")
doc.txtItemNum=Str(result. GetValue(" ITEM"))
doc.txtCollDesc1=result.Ge tValue("Fi rstofCOLLD ESC1")
doc.txtCollDesc2=result.Ge tValue("Fi rstofCOLLD ESC2")
NextRow:
result.nextrow
If (Obligor=result.GetValue(" OBLIGOR")) And (Obligation=result.GetValu e("OBLIGAT ION")) And (Item=Str(result.GetValue( "ITEM"))) Then
Goto NextRow
End If
If (Obligor=result.GetValue(" OBLIGOR")) And (Obligation=result.GetValu e("OBLIGAT ION")) And (Item<>Str(result.GetValue ("ITEM"))) Then
Set item=doc.GetFirstItem("txt ItemNum")
Set colldesc1 = doc.getFirstItem("txtcolld esc1")
Set colldesc2 = doc.getFirstItem("txtcolld esc2")
Set CollType = doc.getFirstItem("COLLTYPE ")
Call item.appendTOTextList( Str(result.GetValue("ITEM" )) )
Call colldesc1.appendTOTextList ( result.GetValue("FirstofCO LLDESC1"))
Call colldesc2.appendTOTextList ( result.GetValue("FirstofCO LLDESC2"))
Call CollType.appendTOTextList( result.GetValue("COLLTYPE" ))
Goto NextRow
Else
If (Obligor=result.GetValue(" OBLIGOR")) And (Obligation<>result.GetVal ue("OBLIGA TION")) Then
Set item=doc.GetFirstItem("txt ItemNum")
Set colldesc1 = doc.getFirstItem("txtcolld esc1")
Set colldesc2 = doc.getFirstItem("txtcolld esc2")
Set CollType = doc.getFirstItem("COLLTYPE ")
Set Obligation = doc.GetFirstItem("OBLIGATI ON")
Call item.appendTOTextList( Str(result.GetValue("ITEM" )) )
Call colldesc1.appendTOTextList ( result.GetValue("FirstofCO LLDESC1"))
Call colldesc2.appendTOTextList ( result.GetValue("FirstofCO LLDESC2"))
Call CollType.appendTOTextList( result.GetValue("COLLTYPE" ))
Call Obligation.appendTOTextLis t( result.GetValue("OBLIGATIO N"))
Goto NextRow
Else
If (Obligor<>result.GetValue( "OBLIGOR") ) Then
doc.Form = "Automated_OARF"
doc.FormName ="Automated_OARF"
Call doc.Save(True, True)
End If
End If
End If
Loop Until EndofResultSet
End If
End Sub
This new code works relatively well with a few exceptions. I want it keep items with the same obligor number on the same document. Once the obligor changes, it can save and close the form (and send out the notification, which will be a different form with a link to the original). Right now it is looping and creating a new document on each record, regardless of the criteria I built. Also, it gets on the last record, repeating it continuously until I ctrl-alt-delete and end the task.
Thanks for the help again!!
Puck
Sub Initialize
Dim s As New notessession
Dim db As NotesDatabase
Dim doc As NotesDocument
Dim Con As New ODBCConnection
Dim qry As New ODBCQuery
Dim result As New ODBCResultSet
Dim item, colldesc1, colldesc2, Obligation, CollType As NotesItem
Set db=s.currentdatabase
Set qry.Connection=con
Set result.query=qry
con.ConnectTo("OARFAutomat
qry.SQL= "SELECT tblMaster.BANK, tblMaster.OBLIGOR, tblMaster.OBLIGATION, tblMaster.CUSTNAME, " _
& "tblMaster.PROCTYPE, tblMaster.COLLTYPE, tblMaster.MATDATE, tblMaster.ITEM, " _
& "tblMaster.FirstOfCOLLDESC
& "tblMaster.PREPAY, tblMaster.txt_EMAILADD, tblMaster.txtReadyToSendIn
& "FROM tblMaster " _
& "GROUP BY tblMaster.BANK, tblMaster.OBLIGOR, tblMaster.OBLIGATION, tblMaster.CUSTNAME, " _
& "tblMaster.PROCTYPE, tblMaster.COLLTYPE, tblMaster.MATDATE, tblMaster.ITEM, " _
& "tblMaster.FirstOfCOLLDESC
& "tblMaster.PREPAY, tblMaster.txt_EMAILADD, tblMaster.txtReadyToSendIn
& "HAVING (((tblMaster.txtReadyToSen
result.execute
If result.IsResultSetAvailabl
result.FirstRow
Do
Set doc=db.CreateDocument
doc.SendTo=result.GetValue
doc.txtBankNum=result.GetV
doc.txtObligor=result.GetV
doc.txtObligation=result.G
doc.txtCustomerName=result
doc.txtCollateralType=resu
doc.txtNoteDate=result.Get
doc.txtPrepayCode=result.G
doc.txtRM=result.GetValue(
doc.txtItemNum=Str(result.
doc.txtCollDesc1=result.Ge
doc.txtCollDesc2=result.Ge
NextRow:
result.nextrow
If (Obligor=result.GetValue("
Goto NextRow
End If
If (Obligor=result.GetValue("
Set item=doc.GetFirstItem("txt
Set colldesc1 = doc.getFirstItem("txtcolld
Set colldesc2 = doc.getFirstItem("txtcolld
Set CollType = doc.getFirstItem("COLLTYPE
Call item.appendTOTextList( Str(result.GetValue("ITEM"
Call colldesc1.appendTOTextList
Call colldesc2.appendTOTextList
Call CollType.appendTOTextList(
Goto NextRow
Else
If (Obligor=result.GetValue("
Set item=doc.GetFirstItem("txt
Set colldesc1 = doc.getFirstItem("txtcolld
Set colldesc2 = doc.getFirstItem("txtcolld
Set CollType = doc.getFirstItem("COLLTYPE
Set Obligation = doc.GetFirstItem("OBLIGATI
Call item.appendTOTextList( Str(result.GetValue("ITEM"
Call colldesc1.appendTOTextList
Call colldesc2.appendTOTextList
Call CollType.appendTOTextList(
Call Obligation.appendTOTextLis
Goto NextRow
Else
If (Obligor<>result.GetValue(
doc.Form = "Automated_OARF"
doc.FormName ="Automated_OARF"
Call doc.Save(True, True)
End If
End If
End If
Loop Until EndofResultSet
End If
End Sub
This new code works relatively well with a few exceptions. I want it keep items with the same obligor number on the same document. Once the obligor changes, it can save and close the form (and send out the notification, which will be a different form with a link to the original). Right now it is looping and creating a new document on each record, regardless of the criteria I built. Also, it gets on the last record, repeating it continuously until I ctrl-alt-delete and end the task.
Thanks for the help again!!
Puck
ASKER
Ok. One issue solved. I was able to stop the loop by changing the Loop until to "Loop until result.EndofData."
I was close before, but no banana.
I was close before, but no banana.
So what is the problem here ?
obligation = result.GetValue("OBLIGATIO
If obligor != obligation then
' Evaluate item
else
' New Item#, new colldesc1, colldesc2 inserted
set item = doc.getFirstItem("txtItemN
set colldesc1 = doc.getFirstItem("txtcolld
set colldesc2 = doc.getFirstItem("txtcolld
call item.appendTOTextList( Str(result.GetValue("ITEM"
call colldesc1.appendTOTextList
call colldesc2.appendTOTextList
SendDoc = True
End If
' Insert this at the end of the sub i.e after resulset endif
If SendDoc then
Recipients = "Recipient Name"
Call doc.Send( true, Recipients)
End if
~Hemanth