Solved

Notes Clinet Search

Posted on 2006-07-14
19
208 Views
Last Modified: 2013-12-18
I have a home made portal in Notes 6.5 used on the client. It is frame based, I have one frame that I have populate dwith a "search engine" (lets call it that) I have a form with a field that the user will input a persons name, either last or first, department, etc, then they click on a button to start the search: this is the button script:  
Sub Click(Source As Button)
      Dim ws As New notesuiworkspace
      Dim uidoc As notesuidocument
      Dim session As New NotesSession
      Dim db As NotesDatabase
      Dim dc As NotesDocumentCollection
      Dim news As NotesNewsletter
      Dim doc As NotesDocument
      Set db = session.CurrentDatabase
      Set uidoc = ws.currentdocument
      Set doc = uidoc.document
      searchFormula$ = doc.BasicSearch(0)
      If searchFormula$ = "" Then
            Exit Sub
      End If
      Call uidoc.close
      Set dc = db.FTSearch(searchFormula$, 0)
      Set news = New NotesNewsletter(dc)
      news.DoScore = False
      news.DoSubject = True
      news.SubjectItemName = "DeptTitle"
      Set doc = news.FormatMsgWithDoclinks(db)
      doc.subject = "Search Results For:  " & searchFormula$
      doc.form = "Search"
      doc.SaveOptions = "0"
      Set uidoc = ws.EditDocument(False, doc)
End Sub

This script searches the current db, I want to search my Employee database (by name view) and return either a record or a list of results either is fine with me....All help is appreciated......
0
Comment
Question by:padillrr
  • 9
  • 7
19 Comments
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 17113703
You don't say what your problem is, so I assume that it is the syntax of the searchFormula you need. For a complete description, see the standard Help database (not the Designer!), in the Index, and go to Search queries.

In your case, it will be something like (you fill in the gaps and the correct document fields):

    If personname<>"" Then
        searchFormula$= {((Field LastName = "} & personname & {") or (Field FirstName = "} & personname & {"))}
    End If
    If deptname<>"" Then
        If searchFormula$ <>"" Then searchFormula$ = searchFormula$ & " and "
        searchFormula$= {(Field Department = "} & deptname & {")}
    End If
   

To search a view, you need:
    Dim view As NotesView
    Set view= db.GetView("ByName")
    Set dc= view.FTSearch(searchFormula$, 0)
0
 

Author Comment

by:padillrr
ID: 17122166
This is what I have for a script:

Sub Click(Source As Button)
      Dim ws As New notesuiworkspace
      Dim uidoc As notesuidocument
      Dim session As New NotesSession
      Dim db As New NotesDatabase("ORLLND01","emplook.nsf")
      Dim dc As NotesDocumentCollection
      Dim news As NotesNewsletter
      Dim doc As NotesDocument
      Dim View As NotesView
      'Set db = session.CurrentDatabase
      'Set uidoc = ws.currentdocument
      'Set doc = uidoc.document
      
      Set view= db.GetView("By Last Name")
'      Set dc= view.FTSearch(searchFormula$, 0)
      
      If personname<>"" Then
            searchFormula$= {((Field LastName = "} & personname & {") or (Field FirstName = "} & personname & {"))}
      End If
      If department<>"" Then
            If searchFormula$ <>"" Then searchFormula$ = searchFormula$ & " and "
            searchFormula$= {(Field Department = "} & deptname & {")}
            
'searchFormula$ = doc.BasicSearch(0)
      'If searchFormula$ = "" Then
            Exit Sub
      End If
      Call uidoc.close
      Set dc = db.FTSearch(searchFormula$, 0)
      Set news = New NotesNewsletter(dc)
      news.DoScore = False
      news.DoSubject = True
      news.SubjectItemName = "DeptTitle"
      Set doc = news.FormatMsgWithDoclinks(db)
      doc.subject = "Search Results For:  " & searchFormula$
      doc.form = "Search"
      doc.SaveOptions = "0"
      Set uidoc = ws.EditDocument(False, doc)
End Sub

This is on a button on a form that is on a frame in my portal page, I there is a field the user will input a persons name I need the Search button to look in my emplook db on the By Last Name view and return the results, I am getting a variable not set error but can't figure it out...
0
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 17122623
Always when you get such an error, add some errortrapping:

At the start:
    On Error Goto onerror

At the end, right before the End Sub:

exitsub:
    Exit Sub
onerror:
    Print "Error " & Error$ & " on line " & Erl
    Resume exitsub

What's the Exit Sub doing, in the middle?? Another leftover? ;)
0
 

Author Comment

by:padillrr
ID: 17122736
yep I cleaned it up a  little here it is now....

Sub Click(Source As Button)
      
      Dim db As New NotesDatabase("ORLLND01","emplook.nsf")
      Dim dc As NotesDocumentCollection
      Dim doc As NotesDocument
      Dim View As NotesView
      

      Set view= db.GetView("By Last Name")

                On Error Goto onerror
      
      If personname<>"" Then
            searchFormula$= {((Field LastName = "} & personname & {") or (Field FirstName = "} & personname & {"))}
      End If
      If department<>"" Then
            If searchFormula$ <>"" Then searchFormula$ = searchFormula$ & " and "
            searchFormula$= {(Field Department = "} & deptname & {")}
            
            searchFormula$ = doc.BasicSearch(0)
            
      End If
      
      Set dc = db.FTSearch(searchFormula$, 0)
      doc.subject = "Search Results For:  " & searchFormula$
      doc.form = "Search"
      doc.SaveOptions = "0"

               exitsub:
                  Exit Sub
                    onerror:
                    Print "Error " & Error$ & " on line " & Erl
              Resume exitsub

            End Sub

get the error:  Error Object variable not set on line 22
0
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 17122878
The least you could have done is tell me which line is line 22... ;)

And you cleanup was a bit too rigourous, I think.

Option Declare ' always add this option!

Sub Click(Source As Button)
     Dim ws As New notesuiworkspace
     Dim uidoc As notesuidocument
     Dim session As New NotesSession
     Dim db As New NotesDatabase("ORLLND01","emplook.nsf")
     Dim dc As NotesDocumentCollection
     Dim news As NotesNewsletter
     Dim doc As NotesDocument
     Dim View As NotesView
     
    On Error Goto onerror
     Set view= db.GetView("By Last Name")
     
     If personname<>"" Then
          searchFormula$= {((Field LastName = "} & personname & {") or (Field FirstName = "} & personname & {"))}
     End If
     If department<>"" Then
          If searchFormula$ <>"" Then searchFormula$ = searchFormula$ & " and "
          searchFormula$= {(Field Department = "} & deptname & {")}
         
     End If
     Call uidoc.close
     If searchFormula$ = "" Then Exit Sub
     Set dc = db.FTSearch(searchFormula$, 0)
     Set news = New NotesNewsletter(dc)
     news.DoScore = False
     news.DoSubject = True
     news.SubjectItemName = "DeptTitle"
     Set doc = news.FormatMsgWithDoclinks(db)
     doc.subject = "Search Results For:  " & searchFormula$
     doc.form = "Search"
     doc.SaveOptions = "0"
     Set uidoc = ws.EditDocument(False, doc)
End Sub

personname?? department?? These two variables don't have a value (yet), up to you to get them from the current document.
0
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 17122886
O frak, I forgot the errortrapping stuff at the end...

     doc.SaveOptions = "0"
     Set uidoc = ws.EditDocument(False, doc)
exitsub:
    Exit Sub
onerror:
    Print "Error " & Error$ & " on line " & Erl
    Resume exitsub
End Sub
0
 

Author Comment

by:padillrr
ID: 17124144
variable not declared : SearchFormula on this line:

If personname<>"" Then
          searchFormula$= {((Field LastName = "} & personname & {") or (Field FirstName = "} & personname & {"))}
     End If

0
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 17125082
Dim SearchFormula As String
0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 

Author Comment

by:padillrr
ID: 17125279
type mismatch on these lines: ***

 ***If personname<>"" Then
          ***searchFormula$= {((Field LastName = "} & personname & {") or (Field FirstName = "} & personname & {"))}
     End If
    If department<>"" Then
          ***If searchFormula$ <>"" Then searchFormula$ = searchFormula$ & " and "
         *** searchFormula$= {(Field Department = "} & deptname & {")}

Here's what  I have so far:

Sub Click(Source As Button)
      Dim ws As New notesuiworkspace
      Dim uidoc As notesuidocument
      Dim session As New NotesSession
      Dim db As New NotesDatabase("ORLLND01","emplook.nsf")
      Dim Department As NotesItem
      Dim personname As NotesItem
      'Dim LastName As NotesItem
      'Dim FirstName As NotesItem
      Dim dc As NotesDocumentCollection
      Dim news As NotesNewsletter
      Dim doc As NotesDocument
      Dim View As NotesView
      Dim Searchformula As String
      On Error Goto onerror
      Set view= db.GetView("By Last Name")
      
      If personname<>"" Then
            searchFormula$= {((Field LastName = "} & personname & {") or (Field FirstName = "} & personname & {"))}
      End If
      If department<>"" Then
            If searchFormula$ <>"" Then searchFormula$ = searchFormula$ & " and "
            searchFormula$= {(Field Department = "} & department & {")}
            
      End If
      Call uidoc.close
      If searchFormula$ = "" Then Exit Sub
      Set dc = db.FTSearch(searchFormula$, 0)
      Set news = New NotesNewsletter(dc)
      news.DoScore = False
      news.DoSubject = True
      news.SubjectItemName = "DeptTitle"
      Set doc = news.FormatMsgWithDoclinks(db)
      doc.subject = "Search Results For:  " & searchFormula$
      doc.form = "Search"
      doc.SaveOptions = "0"
      Set uidoc = ws.EditDocument(False, doc)
      
exitsub:
      Exit Sub
onerror:
      Print "Error " & Error$ & " on line " & Erl
      Resume exitsub
End Sub
0
 
LVL 46

Accepted Solution

by:
Sjef Bosman earned 250 total points
ID: 17126275
I just KNOW you can do better than that :)

Sub Click(Source As Button)
     Dim ws As New notesuiworkspace
     Dim uidoc As notesuidocument
     Dim session As New NotesSession
     Dim db As New NotesDatabase("ORLLND01","emplook.nsf")
     Dim Department As String ' NotesItem ???
     Dim personname As String ' NotesItem???
     'Dim LastName As NotesItem
     'Dim FirstName As NotesItem
     Dim dc As NotesDocumentCollection
     Dim news As NotesNewsletter
     Dim doc As NotesDocument
     Dim View As NotesView
     Dim Searchformula As String
     On Error Goto onerror
     Set view= db.GetView("By Last Name")
     
     ' --- you kinda forgot to initialize lots of variables...
     Set uidoc= ws.currentdocument
     Set doc= uidoc.document    
     personname= doc.PutHereTheFieldWithThePersonsName(0)
     department= doc.SomeThingLikeTheLineBefore(0)
     ' --- then we can continue
     If personname<>"" Then
          searchFormula= {((Field LastName = "} & personname & {") or (Field FirstName = "} & personname & {"))}
     End If
     If department<>"" Then
          If searchFormula <>"" Then searchFormula = searchFormula & " and "
          searchFormula= {(Field Department = "} & department & {")}
         
     End If
     Call uidoc.close
     If searchFormula = "" Then Exit Sub
     Set dc = db.FTSearch(searchFormula$, 0)
     Set news = New NotesNewsletter(dc)
     news.DoScore = False
     news.DoSubject = True
     news.SubjectItemName = "DeptTitle"
     Set doc = news.FormatMsgWithDoclinks(db)
     doc.subject = "Search Results For:  " & searchFormula$
     doc.form = "Search"
     doc.SaveOptions = "0"
     Set uidoc = ws.EditDocument(False, doc)
     
exitsub:
     Exit Sub
onerror:
     Print "Error " & Error$ & " on line " & Erl
     Resume exitsub
End Sub

I think you mentioned that you need to search only a view? We'll correct that later.
0
 

Author Comment

by:padillrr
ID: 17130417
Thanks Sjef, it's true if you don't use it, you lose it and I have not been writing lotruscript since the class....

Well I got the code in place and tried it but now it just exits out of my frameset back to the client, it closes th eapplication once I hit the search button.

The intent is to allow the user to input a person name and display that particular record.

0
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 17131363
> I have not been writing lotruscript since the class...
You bad!

> it closes the app...
For the time being, remove the uidoc.close
0
 

Author Comment

by:padillrr
ID: 17131433
Yeah I know been mainl ysupporting stuff so it doesn't allow me to create....now that I am creating I feel lost again....anyway I commented the uidoc.close and get no errors but also no results....
0
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 17134331
Use the debugger, and try to find out what isn't working the way it should. By the way, I didn't look into your code in detail, so I can't tell you that your code is doing something sensible or not. Where did you find it, and what is it supposed to do?

If it does nothing, then probably it will bail out when checking searchFormula="". Did you use the right fields on the form?
0
 

Author Comment

by:padillrr
ID: 17403475
Marilyn, I never really got the answer I was looking for even though I did try all the suggestions here. I am still in need of some assistance in this. A search on a client application that will search another database for results. i.e in our Portal applicatin I want to put a search employees sectin that will search our employee lookup application for that person and return a response............I've seen it done on the web I need it for the client.....
0
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 17404006
Then what's the status, and what code do you have at the moment? Where are you stuck?
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

You’ve got a lotus Domino web server, and you have been told that “leverage browser caching” is a must do. This means that we have to tell the browser everywhere in the web to use cache. In other words, we set (and send) an expiration date in the HT…
Article by: Rob
Notes 8.5 Archiving Steps and Tips This article covers setting up a Notes archive, and helps understand some of the menu choices making setting up and maintaining a Notes archive file easier.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now