Stuck on an IF statement in Lotus Domino

105 pts.
Tags:
IF statement
Lotus Domino
Lotus Notes administration
I need to get this statement so that it will only update when a new doc is created. I am having a problem with the IF statement and it is currently update ever doc even if it does have new records. I only wnat the new record(actionitems) to update the agent is below

 

Sub Initialize %REM  REFRESH OSHA INFO  Update ALL OSHA Numbers in Current Agenda Headers %END REM  Const  LOGNAME = "RefreshOshaInfo"    REM Notes Handles  Dim ss As New NotesSession  Dim db As NotesDatabase  Dim vw As NotesView  Dim vc As NotesViewEntryCollection  Dim vcEntry As NotesViewEntry  Dim doc As NotesDocument REM Dim DC As NotesDocumentCollection  Dim RRembview As NotesView  Dim item As Variant  Dim strfield As String  Dim temp As Variant  Dim Count As Integer  Dim agendaloc As Integer  Dim agyear As Integer  Dim agmonth As Integer  Dim locv As NotesView    Dim Headerdoc As NotesDocument  Dim workcount As Integer  REM Other  Dim nTotalNeededUpdate As Integer  Dim nTotalProcessed As Integer  Dim bUpdate As Boolean  Dim ErrorMsg As String  REM Saved Fields  Dim nLostTimeDays As Integer  Dim nNonLostTimeDays As Integer  Dim nYTDAccidents As Integer  Dim nYTDDriverAccidents As Integer  Dim bodyarray As NotesDocument  Dim Ekey As Variant  Dim adoc As NotesDocument  Dim cUpdate As Boolean REM Dim nActionitems As Integer  REM Dim agendaitem As String  Dim ActionItems As Integer  Dim aview As NotesView  Dim workA As Integer  Dim ALcount As Boolean  Dim doccount As Integer    On Error Goto ProcessError    Call AgentLogAction(LOGNAME, "<------Start------>")  Set db = ss.CurrentDatabase      Set aview = db.GetView("RREMB") 'added 2/16/2011      ErrorMsg="View CurrHeaders NOT Found"    Set vw = db.GetView("CurrHeaders")  'All Current Agenda Headers  Set vc = vw.AllEntries    ErrorMsg = "View collection NOT Found"    Set vcEntry = vc.GetFirstEntry    ErrorMsg=""        Do While Not (vcEntry Is Nothing)   Set doc = vcEntry.Document   REM AM changes 2/16/2011   Ekey = doc.Loc(0)& "~" & doc.mtgyy(0) & "~" & doc.mtgmm(0)         Set DC= aview.GetAllDocumentsByKey(Ekey,True)      WorkA = dc.count         If workA = doc.actionitems(0) Then    alcount =True   Else    doc.ActionItems = dc.count        REM doc.ActionItems(0) = dc.Count            End If      nTotalProcessed = nTotalProcessed + 1    REM Save current values      nLostTimeDays= doc.LostTimeDays(0)   nNonLostTimeDays = doc.NonLostTimeDays(0)   nYTDAccidents = doc.YTDAccidents(0)   nYTDDriverAccidents= doc.YTDDriverAccidents(0)      REM Update Osha Numbers for this doc   Call GetOshaInfo(doc.Loc(0), doc)      bUpdate = False   bUpdate = bUpdate Or alcount   bUpdate = bUpdate Or ( nLostTimeDays <> doc.LostTimeDays(0) )   bUpdate = bUpdate Or ( nNonLostTimeDays <> doc.NonLostTimeDays(0) )   bUpdate = bUpdate Or ( nYTDAccidents <> doc.YTDAccidents(0) )   bUpdate = bUpdate Or ( nYTDDriverAccidents <> doc.YTDDriverAccidents(0) )      If bUpdate Then      Call doc.Save (True,False)     nTotalNeededUpdate = nTotalNeededUpdate + 1   End If   Print Right("00000" + Cstr(nTotalProcessed), 5) & " OSHA Headers processed  -  " + Right("00000" + Cstr(nTotalNeededUpdate), 5)  & " OSHA Headers needed updates."   Set vcEntry = vc.GetNextEntry(vcEntry)  Loop     Finish:  Call AgentLogAction(LOGNAME, Right("00000" + Cstr(nTotalProcessed), 5) & " OSHA Headers processed.")  Call AgentLogAction(LOGNAME, Right("00000" + Cstr(nTotalNeededUpdate), 5)  & " OSHA Headers needed updates.")  Call AgentLogAction(LOGNAME, "<------End------->")  Exit Sub   ProcessError:  Stop  Call AgentLogError(LOGNAME,0,  "Line: " & Erl() &  "Error:" & Err() & "=" & Error() )  Resume POExit POExit: End Sub



Software/Hardware used:
Lotus

Answer Wiki

Thanks. We'll let you know when a new response is added.

Have you tried stepping through the code with the debugger on? It’s probably the fastest way to find the problem. Here are some things to consider, though:

For this line:
If workA = doc.actionitems(0) Then

Are you sure actionitems(0) is an integer? You may want to force conversion to an integer or test what type of data it is ahead of time.

BTW, if the above IF statement evaluates to True, then you set a flag (alcount) to True. Later, if this flag is set, bUpdate is set to True, which causes the doc to be saved. Is that what you want?

Discuss This Question: 1  Reply

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • AMcAuley3
    AGENT MORE Spaced OUT Sub Initialize %REM REFRESH OSHA INFO Update ALL OSHA Numbers in Current Agenda Headers %END REM Const LOGNAME = "RefreshOshaInfo" REM Notes Handles Dim ss As New NotesSession Dim db As NotesDatabase Dim vw As NotesView Dim vc As NotesViewEntryCollection Dim vcEntry As NotesViewEntry Dim doc As NotesDocument REM Dim DC As NotesDocumentCollection Dim RRembview As NotesView Dim item As Variant Dim strfield As String Dim temp As Variant Dim Count As Integer Dim agendaloc As Integer Dim agyear As Integer Dim agmonth As Integer Dim locv As NotesView Dim Headerdoc As NotesDocument Dim workcount As Integer REM Other Dim nTotalNeededUpdate As Integer Dim nTotalProcessed As Integer Dim bUpdate As Boolean Dim ErrorMsg As String REM Saved Fields Dim nLostTimeDays As Integer Dim nNonLostTimeDays As Integer Dim nYTDAccidents As Integer Dim nYTDDriverAccidents As Integer Dim bodyarray As NotesDocument Dim Ekey As Variant Dim adoc As NotesDocument Dim cUpdate As Boolean REM Dim nActionitems As Integer REM Dim agendaitem As String Dim ActionItems As Integer Dim aview As NotesView Dim workA As Integer Dim ALcount As Boolean Dim doccount As Integer On Error Goto ProcessError Call AgentLogAction(LOGNAME, "<------Start------>") Set db = ss.CurrentDatabase Set aview = db.GetView("RREMB") 'added 2/16/2011 ErrorMsg="View CurrHeaders NOT Found" Set vw = db.GetView("CurrHeaders") 'All Current Agenda Headers Set vc = vw.AllEntries ErrorMsg = "View collection NOT Found" Set vcEntry = vc.GetFirstEntry ErrorMsg="" Do While Not (vcEntry Is Nothing) Set doc = vcEntry.Document REM AM changes 2/16/2011 Ekey = doc.Loc(0)& "~" & doc.mtgyy(0) & "~" & doc.mtgmm(0) Set DC= aview.GetAllDocumentsByKey(Ekey,True) WorkA = dc.count THIS IS WHERE I NEED THE Help If workA = doc.actionitems(0) Then alcount =True Else doc.ActionItems = dc.count REM doc.ActionItems(0) = dc.Count End If nTotalProcessed = nTotalProcessed + 1 REM Save current values nLostTimeDays= doc.LostTimeDays(0) nNonLostTimeDays = doc.NonLostTimeDays(0) nYTDAccidents = doc.YTDAccidents(0) nYTDDriverAccidents= doc.YTDDriverAccidents(0) REM Update Osha Numbers for this doc Call GetOshaInfo(doc.Loc(0), doc) bUpdate = False bUpdate = bUpdate Or alcount bUpdate = bUpdate Or ( nLostTimeDays <> doc.LostTimeDays(0) ) bUpdate = bUpdate Or ( nNonLostTimeDays <> doc.NonLostTimeDays(0) ) bUpdate = bUpdate Or ( nYTDAccidents <> doc.YTDAccidents(0) ) bUpdate = bUpdate Or ( nYTDDriverAccidents <> doc.YTDDriverAccidents(0) ) If bUpdate Then Call doc.Save (True,False) nTotalNeededUpdate = nTotalNeededUpdate + 1 End If Print Right("00000" + Cstr(nTotalProcessed), 5) & " OSHA Headers processed - " + Right("00000" + Cstr(nTotalNeededUpdate), 5) & " OSHA Headers needed updates." Set vcEntry = vc.GetNextEntry(vcEntry) Loop Finish: Call AgentLogAction(LOGNAME, Right("00000" + Cstr(nTotalProcessed), 5) & " OSHA Headers processed.") Call AgentLogAction(LOGNAME, Right("00000" + Cstr(nTotalNeededUpdate), 5) & " OSHA Headers needed updates.") Call AgentLogAction(LOGNAME, "<------End------->") Exit Sub ProcessError: Stop Call AgentLogError(LOGNAME,0, "Line: " & Erl() & "Error:" & Err() & "=" & Error() ) Resume POExit POExit: End Sub
    105 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following