Return Embeded View Document Counts

Hi Everyone,

I am new to Lotus notes and also lotus script but I have been learning along the way with tutorials provided. However, I am not too confident yet and needed help. I definitely know that this site is an excellent site that queries get answered and alot of help come from here and therefore am posting my queries from time to time.

I have created a script to return documents counts for an embebed view on a form. I would like the script to return the number of documents in the embeded view and return the value in a field called dcount. The embeded view contains a list of forms which are seperate from the parent form but a child to the parent form. What I would like to accomplish is to stop users from creating new child once they reach the maximum number allowed. I have a field on the parent form called maxnumber that I specify how many forms (forms contained within the embeded view) are allowed to be created. Once the max number is reached then a prompt must be displayed when users click on the new button to inform users that max number is reached. Below is the code that is created so far but I need some more assistance to complete it and get it working.

Sub Click(Source As Button)

Dim workspace As New NotesUIWorkspace

Dim session As New NotesSession

Dim db As NotesDatabase

Dim view As NotesView

Dim entry As NotesViewEntry

Dim vc As NotesViewEntryCollection

Dim doc As NotesDocument

Dim count As Variant

'Dim  count As Integer

'count = 0



Set db = session.CurrentDatabase

Set view = db.GetView("LeasebyTenant")

Set vc = view.AllEntries

Set entry = vc.GetFirstEntry()

While Not (entry Is Nothing)

	Set doc = entry.Document

	Set entry = vc.GetNextEntry(entry)

	'count = count + 1

Wend

'doc.DocCount=entry.ChildCount

'Set count=doc.DocCount

count = entry.ChildCount



If count <>Null Then

	If Count => doc.maxnumber Then

		Messagebox "Maximum number of documents created."

		Exit Sub

	End If

	Call workspace.ComposeDocument( "", "", "Lease" )

End If	

End Sub

Please help needed urgently.

Thanks in advance!

S Yoko

Subject: Return Embeded View Document Counts

S Yoko,

I think I would approach this differently. I think I would try to have my dcount field perform this formula:

@Elements(@DbColumn(“Notes”; “”; “LeasebyTenant”; 1))

I’m not sure if it’s faster, but it’s a lot simpler.

regards,

raphael

Subject: RE: Return Embeded View Document Counts

Hi Raphael,

Thanks for your help. I tried your code and it gave a total that is more than the responses. The documents counted should have been the ones embeded on the main form or parent form but instead it seems like it is counting everything in that view and not just the ones selected for that embebed view. Is there a way around it?

YOur help much appreciated.

Thanks.

Yoko

Subject: RE: Return Embeded View Document Counts

If you have a key, then you can do @Elements(@DbLookup()) instead of @Elements(@DbColumn()), which will be faster, too.

regards,

raphael

Subject: RE: Return Embeded View Document Counts

Raphael,

What Key? a key field to do search? Please explain to clarify my understanding…

Thanks!

Yoko

Subject: RE: Return Embeded View Document Counts

Presumably the embedded view in your form showing the child documents is a single category view … that is the view in the DB is categoriesed and the view embeeded in the form only shows some of these docs based on a key value from the form.

Supposing the form only showed child docs for a tenant whose tenant ID was ABC. The field ABC must be some where on the parent form and the formula for the single category view would be the name of the field containing the TenantID.

Therefore your lookup to get the count of only values from child docs whose parent is TenantID=ABC (the key field in this case) would be

@Elements(@DbLookup(“Notes”; “”; “LeasebyTenant”; TenantID ;1))

HTH

Shane

Subject: RE: Return Embeded View Document Counts

Hi Shane,

I have a view that select all of the child form and in that view I have 6 columns. Column 1 is the document id field for the parent form (Common in both forms, parent and child).

So what you have said is correct accept that I have 6 columns created and all columns displayed in the embebed view.

I have tried your method and still gave me error.

What else can I do to accomplish this?

Help much appreciated.

Regards,

Yoko

Subject: RE: Return Embeded View Document Counts

If you want to IRC me and chat this through try shane_hollis2001@yahoo.com

Subject: RE: Return Embeded View Document Counts

Hi,

What is the name of the field that has the ID field in the form and what is its data type?

Also are the columns for the view categorised. If column one is not categorised then try column two possibly.

Either post the code you are using for the lookup on your form or else if you can send me a small copy of your databae with the form, and the view i can sort it out for you. either that or we could do an IRC chat, resolve it that way and then post the results here.

I have to go home now, my wife is waiting but I will look for your post in the morning. I am in NZ so we are GMT + !2 hours.

Subject: Return Embeded View Document Counts

If the documents that you want count are all children of the document that you are on, then why not just use the NotesDocument.Responses collection? It has a Count property that gives you the info you are looking for.

Subject: RE: Return Embeded View Document Counts

Thanks Dave,

How do you apply that method? I know it is a dumb question to ask but am new so needed some spoon feeding here.

Thanks for your help.

Regards,

Yoko

Subject: RE: Return Embeded View Document Counts

Yoko,

Here is some code to get you started. It could be put in any form event handler such as button click event or a QuerySave event.

Dim ws As New NotesUIWorkspace

Dim uidoc As NotesUIDocument

Dim doc As NotesDocument

’ First get a handle on the current document

Set uidoc = ws.CurrentDocument

Set doc = uidoc.Document

If Not doc.Responses Is Nothing Then

MsgBox “The current document has " & Format(doc.Responses.Count) & " responses.”

Else

MsgBox “The current document does not have any responses.”

End If

I hope this helps.