• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 348
  • Last Modified:

Help pls, problems with QuerySaveAgent!!

Hi,

I have a database that allows users to create document on web. So in my form, I have $$QuerySaveAgent field to store my agent's name. The agent is working fine except 1 part.
In my form, I have 4 fields - Event name, Event date, Event time, VIP name.

In my agent, I need to check whether the same VIP name entered in the new document, exists in the existing documents with same date & time (that means one VIP name appears in more than 1 documents - new & existing docs, which those documents are having the same Event date & event time).

Then after this checking, I have the coding for creating an Audit Trail document, at the bottom of the agent.

Everything seems working, but not for the duplicate event checking. I tried to create an Event doc that has the same Date, Time, and VIP with another existing Event doc. By right, the system should display an error message and stop creating document. But it did not. And it just allows the checking passed through and the document is created.

Here is my checking part in the agent:
-----------------------------------------------------------------------
     Dim sess As New NotesSession
     Dim db As NotesDatabase
     Dim view As NotesView, viewE As NotesView
     Dim dc As NotesDocumentCollection
     Dim note As NotesDocument, docE As NotesDocument, docVIP As NotesDocument
     Dim nameUsr As New NotesName(sess.Username)
     Dim rtitemName, rtitemLoc, rtitemFrom, rtitemTime, rtitemVIP, rtitemRole, rtitemCover, rtitemContact, rtitemStatus
     Dim Ename As String, ELoc As String, EVip As String, ERole As String, ECover As String, EContact As String, EStatus As String
     Dim EFrom, ETime, dateto, speech As String, contactno As Integer, remark As String
     Dim found As Integer, count As Integer, rtitemAuthor As NotesItem
     Dim i As Integer, keyE (1 To 3) As String
     
     Set db = sess.CurrentDatabase
     Set note = sess.DocumentContext    
     
     Set viewE = db.GetView("EventDate")
     keyE(1) = Cstr(note.E_datEFrom(0))
     keyE(2) = Cstr(note.E_datETime(0))
     keyE(3) = Cstr(note.E_kwEVIP(0))
     Set dc = viewE.GetAllDocumentsByKey(keyE, True)
     If Not(dc Is Nothing) Or (dc.Count <> 0) Then
          Print "[http://10.23.1.152/BudgetD/DME.nsf/WebErrmsg/DuplicateEvent]"
          Exit Sub
     End If
-----------------------------------------------------------------------

Could someone help me to debug this?
Thanks a lot.
0
kspuea
Asked:
kspuea
  • 5
  • 4
  • 3
  • +1
1 Solution
 
kspueaAuthor Commented:
I'm using Lotus Notes 4.6.
0
 
AntonysinghCommented:
Hi,

Have you indexed your database?. and also check searching keyfields should appears first in view and should be sorted any order.

Regards,
Antony.
0
 
anuuCommented:
Hi!

1. Try displaying the dc.count and check whether any documents are found at all.
2. If the dc.count > 0, and still the code is not functioning the way it should, try searching for a single value (say) VIP and once found, check for the remaining two values, as opposed to checking them all at one shot.
happy debugging!
anu
0
2018 Annual Membership Survey

Here at Experts Exchange, we strive to give members the best experience. Help us improve the site by taking this survey today! (Bonus: Be entered to win a great tech prize for participating!)

 
ArunkumarCommented:
Hi kspuea !

I agree to Antony singh,  Check the view to find wether all the three keys are sorted in the order of passing.
That should give the solution.

Cheers !
Arun

Hai Antony !
I am in US working for Prudential Securities as a Domino Administration Consultant !

:)

0
 
ArunkumarCommented:
And are you sure in using DocumentContext ?  I doubt with it.  Please find someother way to approach the doc.

Arun :)
0
 
kspueaAuthor Commented:
Hi Antonysingh, anuu, & Arunkumar,

Yes, I have indexed my database and all the keyfields are appearing as first few columns & sorted acending in my view.

I also tried to display the dc.count, it's 0 eventhough I have a document that having the same date, time, & VIP name. And I have tried to search by only 1 value first(eg. date) then compare the rest. But it still doesn't work.

I'm using DocumentContext method. Is it something wrong with it? Can I use DocumentContext to get the document by key?
0
 
kspueaAuthor Commented:
Hi all,

Now it works! I searched docs by using VIP name first then compare the rest, it works amazingly!!

However I created another problem. When the error message is displayed, the DocumentContext is actually saved in the back-end. Its Form property is "WebEvent", instead of "Event" form name.
How could I get rid of this problem? I don't want the Web document to be saved if the error message is displayed.

I have put "Exit Sub" after the line displaying error message, but seems like the web document is still saved.

I already have a SaveOption field in my WebEvent form. Its value is 0.
Is that correct? Is that can't prevent the document to be saving?
0
 
kspueaAuthor Commented:
Hi all,

Here is my complete agent:

     On Error Goto Err_Handler
     
     Dim sess As New NotesSession
     Dim db As NotesDatabase
     Dim view As NotesView, viewE As NotesView
     Dim dc As NotesDocumentCollection
     Dim note As NotesDocument, docE As NotesDocument, docVIP As NotesDocument
     Dim nameUsr As New NotesName(sess.Username)    
     Dim Ename As String, ELoc As String, EVip As String, ERole As String, ECover As String, EContact As String, EStatus As String
     Dim EFrom, ETime, dateto, speech As String, contactno As Integer, remark As String
     Dim found As Integer, count As Integer, rtitemAuthor As NotesItem
     Dim i As Integer, keyE (1 To 3) As String
     
     Set db = sess.CurrentDatabase
     Set note = sess.DocumentContext          
     
     Set viewE = db.GetView("EventDate")          
     Set dc = viewE.GetAllDocumentsByKey(note.E_kwEVIP(0), True)
   
     If Not(dc Is Nothing) Or (dc.Count <> 0) Then
          For i = 1 To dc.Count
               Set docE = dc.GetNthDocument(i)
               If docE.E_datETime(0) = note.E_datETime(0) Then    
                    If docE.E_datEFrom(0) = note.E_datEFrom(0) Then
                         found = 1
                    End If
               End If
          Next
         
          If found  = 1 Then
               Print "[http://10.23.1.152/BudgetD/DME.nsf/WebErrmsg/DuplicateEvent]"
               Exit Sub
          End If          
     End If
     
     Dim doc As New NotesDocument(db)
     doc.Form = "frmAudit"
     If note.IsNewNote = True Then
          doc.AT_txtUserID = note.E_txtLastUpBy(0)
          doc.AT_txtEName = note.E_txtEName(0)
          doc.AT_txtDate = Format$(Today, "dd/mm/yyyy")
          doc.AT_txtTime = Format$(Now, "hh:mm AM/PM")
          doc.AT_txtAction = "Create Event"
          Call doc.Save(True, False)
     Else          
          doc.AT_txtUserID = nameUsr.Abbreviated
          doc.AT_txtEName = note.E_txtEName(0)
          doc.AT_txtDate = Format$(Today, "dd/mm/yyyy")
          doc.AT_txtTime = Format$(Now, "hh:mm AM/PM")
          doc.AT_txtAction = "Edit & Save Event"
          Call doc.Save(True, False)
     End If
     
     note.Form = "Event"          
     Set view = db.GetView("vVIP")
     Set docVIP = view.GetDocumentByKey(note.E_kwEVIP(0), True)
     If Not(docVIP Is Nothing) Then
          note.E_txtVIPRank = Cstr(docVIP.VIP_numRank(0))
     End If
     
     Call note.Save( True, False )
     Exit Sub
     
Err_Handler:
     Print Error$
     Exit Sub
0
 
AntonysinghCommented:
Hi,
Create SaveOptions field with default value as 0 in your form.

If you don't want to save any form which is not satishfied your condition, then leave the SaveOptions value as 0. If want save any form, replace "SaveOptions" field value as 1 and save the form.

Hi Arun,

Happy to hear from you. pl mail me man!. I am also slowly moving to Admin. area.

Regards,
Antony.

 
0
 
kspueaAuthor Commented:
Hi,

I have the SaveOptions field in my form already. And its value is 0. However, it still doesn't work properly.

When I create a document on web, if there is no error messages displayed, the document will be saved using Form "Event" instead of using "WebEvent" form(data entry form on web), which is correct.

On the other hand, if the duplicate event is occurred, the Form "Event" will not be saved, but the Form "WebEvent" is saved(the form that I using for data entry on web).

Could I get rid of this problem? Thks.
0
 
anuuCommented:
Hi,

I think the problem lies with the For loop. In the For loop, the variable 'found' is set to '1' only once no matter how many documents you find. However, what you want is to print "[http://10.23.1.152/BudgetD/DME.nsf/WebErrmsg/DuplicateEvent]" and Exit Sub as soon as that document is encountered, everytime. So try doing this:
In the for loop
when found = 1 then
  print url...dulpicate event
  exit sub
else
  include the new note part...  
   depending on what you want to
   achieve when found != 1
end if


0
 
ArunkumarCommented:
Hi kspuea !
Check this out it not != as in @Formula.
It should be <>.
-Arun
0
 
anuuCommented:
Kspuea & Arun,

If you take a look at my comment, I have suggested a logic to handle the agent properly not the code.

Arun, your answer is indeed not any 'answer' at all!
0
 
ArunkumarCommented:
Hi Anuu !

I know that it is not an answer to the question.

But . . . . .

Sorry, this will not happen again.

:)
Arun
0

Featured Post

[Webinar] Kill tickets & tabs using PowerShell

Are you tired of cycling through the same browser tabs everyday to close the same repetitive tickets? In this webinar JumpCloud will show how you can leverage RESTful APIs to build your own PowerShell modules to kill tickets & tabs using the PowerShell command Invoke-RestMethod.

  • 5
  • 4
  • 3
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now