FORUM PLAN UPDATE
Date revision: This forum will remain open to new posts and responses until December 1, 2018. (After that date, you will still be able to view and search the forum.) Also, we're taking a second look at the best place to host future conversation. For now, keep using this forum, and stay tuned for more news.


Jan 26, 2018, 9:03 AM
5 Posts

NotesDatabase.Search() yielding inconsistent results for custom fields

  • Category: Domino Designer
  • Platform: Windows
  • Release: 9.0
  • Role: Developer
  • Tags: database search
  • Replies: 1

I have made modifications to my mail NSF. I put a menu with buttons to my AppointmentForm that just run a formula that creates an extra field item "MY_CUSTOM_ITEM" with a given value depending on the menu selection.

I have a program written in c# using Domino interop that looks more or less like this:

    NotesSession session = new NotesSession();
    session.Initialize("");
    NotesDatabase db = session.GetDatabase(servername, "mymail.nsf", false);

That is done once, and 'session' and 'db' are stored in a class variable. Then I have a loop that periodically does something like this:

    NotesDocumentCollection col = db.Search("Form = \"Appointment\" & StartTime < @Now & EndTime > @Now & !@Contains(MY_CUSTOM_ITEM;'somevalue')", null, 0);
    object[] obj = (object[])doc.GetItemValue("MY_CUSTOM_ITEM");
    string str = (string)obj[0];

If I set MY_CUSTOM_ITEM to 'anothervalue', save the appointment and start the program, I get str == 'anothervalue'. But if I change the appointment to contain, for example, MY_CUSTOM_ITEM='yetanothervalue', the following iterations of Search() will yield inconsistent results. Most of the time I get the initial result all the time I re-run db.Search(), which is one appointment with str=='anothervalue'. Sometimes I get str=='yetanothervalue', only to see str=='anothervalue' in the next iteration, without me changing anything about the appointment.

I tried the same program with some standard items from Notes appointment. In my case I tested with 'BookFreeTime', which is the item set when you click 'Mark available' in the appointment. In that case I didn't have any problems. Whenever I saved the appointment, Search() yielded a new collection with the updated appointment in it, whith the correct value of 'BookFreeTime'.

The only way I managed to make it work with MY_CUSTOM_ITEM was to instantiate a new NotesSession() on every iteration of the loop. But people are complaining of the amount of sessions being created, and I'm wondering if there is something I could do to make it work without instantiating one session in each iteration, but reusing the same session created at the beginning of the program execution.

Is there something like session.Refresh() or db.Refresh() that could do the trick?

Jan 30, 2018, 8:09 AM
21 Posts
How about trying another approach

Another way (both are still load intensive on the server) is to create a view with its selection formula set to the search formula that you're using.

When you want to look up, just refresh the view, and go through the entries...


FORUM PLAN UPDATE
Date revision: This forum will remain open to new posts and responses until December 1, 2018. (After that date, you will still be able to view and search the forum.) Also, we're taking a second look at the best place to host future conversation. For now, keep using this forum, and stay tuned for more news.