GetDocumentByKeys

Hi All,

I am facing problem which reteriving document from a view through getDocumentbyKeys.

What I have done is : -

I have a form which has user name which is Text field and second is EntryDate which is Date/Time. After creating documents it is showing in the view like

Vikas K Sinha 12/17/2007

Dan 12/18/2007

Stan 11/08/2007

What I would like to do is i want to fetch the document which is created by Stan on Dated 12/18/2007

I used array of keys like

dim key(2) as string

key(0) = “Stan”

key(1) = Date(today) ’ which return today date let say to day is 12/18/2007

dim dc as notesdocumentcollection

set dc = view1.getDocumentbykeys(key,true)

set doc = dc.getFirstDocument

If I check

if doc is nothing then

msgbox “Document not found”

end if

then msgbox prompt document not found which means key is not working properly.

I have also make view 1st column and second column shorted but as you second is datetime column I am confused how to use for this date time

I will be very thankful to you for you help

With Regards

Vikas

Subject: GetDocumentByKeys

Convert the date to a string in both the view (@text) and the Lotusscript (Cstr) and it will work.

Subject: GetDocumentByKeys

Hi Vikas,

First of all, let me tell you, There is no method like "getDocumentbykeys". I believe you have only two methods. 

a. GetDocumentByKey

b. GetAllDocumentsByKey

So, when using DocumentCollection you can use GetAllDocumentsByKey method to get all the documents under a single/multiple category. So ive just tried a simple code, which will work. Find the same below.

            Dim ss As New NotesSession

Dim db As NotesDatabase

Dim vw As NotesView

Dim doc As NotesDocument

Dim dc As NotesDocumentCollection

Dim keys(1 To 2 ) As Variant





Set db=ss.CurrentDatabase

Set vw=db.GetView("User")

keys(1)="Dan"

keys(2)="12/21/2007"



Set dc=vw.GetAllDocumentsByKey(keys,True)

If dc Is Nothing Then

Msgbox "No documents returned for query."

Else



Set doc=dc.GetFirstDocument

While Not doc Is Nothing

Msgbox "Document found for input query. " & doc.Title(0)

Set doc=dc.GetNextDocument(doc)

Wend

End If

here, i haven’t done error handling for view, db etc. The form and view design details as follows:

In relation to the above code:

a. Create a form named “User” containing fields, that will hold values like name, date and a Title.(create a field called Title, as we will retrieve the field value in the code.)

b. Map the necessary fields to the view column. create a view named “User” and modify the selection formula to pick documents from the “User” form.

c. Now the first column will be “Name” which will show the user name value. It should be sorted(either Ascending/Descending). Can be categorized too. Just check the option “Show twisties when row is expandable for a better presentation”.

d. The second column will be “Date” and will show the date of creation.(here i had created a field called “dt” and gave a default value @Today and mapped it here."). Again it should be sorted(either Asc/Des) and can be categorized too.(twistie option can be fine too.)

d. Create a third column to show the title value. That need not be sorted or categorized.

Now save the view, you are done. Then you can check with the code. Create some documents with all three values and find the code retrieving the Title values from the documents matching a specific key.

Hope that helps.

Jason.

Subject: GetDocumentByKeys

Hi Vikas,

Just found an issue with the code. The field used to show the date was actually a Text field. For a Date/Time field. A line in the code needs to be altered.

Just change the line

keys(2)=“12/21/2007” to

keys(2)=Datevalue(“12/21/2007”)

because for date/time fields the the key array wont match. So just convert the string representation to an date/time value using the DateValue function. I believe you can use any other date conversion method too. Anyway this will work.

HTH,

Jason.

Subject: GetDocumentByKeys

Thanks all,

Your given code supported me now its working

With Regards,

Vikas