Can someone point me to an example, please

I’m trying to get a count from a document collection of all responses and can’t get script to work.

Basically, a button on a parent document when clicked creates 5 response documents. That works

When all of the response documents have a status of “closed” I want to genrate an email, I created a view with first column is @Text($Ref) but have no clue as to how to get a script to tell when all docs have been completed. The view only shows Open documents

In theory when the last document of the 5 responses is closed my script, int he queryclose, kicks off and if it finds NO documents should work but I’m having trouble writing the scriopt.can someone point me to an example.

Thank you

ccl

Subject: can someone point me to an example, please

Carl, here’s a mockup of some code that should hopefully work - it’s based on something I’m using in a live database.

Sub Queryclose(Source As Notesuidocument, Continue As Variant)

Dim session As New NotesSession

Dim db As NotesDatabase

Dim view as NotesView

Dim response As NotesDocument

Dim LkupColl as NotesDocumentCollection



Set db = session.CurrentDatabase

Set view = db.GetView(“Your ByRef Viewname”)

Set response = source.Document	



Set LkupColl = view.GetAllDocumentsByKey( response.~$REF(0) )		

If LkupColl is Nothing then

	'you are done, do what you need to do here

End If

End Sub

Subject: Mary Anne, Here is my code:

I got it to work but here is the end result, I modified your code, wiothout it I was dead:

Dim session As New NotesSession

Dim db As NotesDatabase

Dim v As NotesView

Dim doc As NotesDocument

Dim dc As NotesDocumentCollection

Dim parent As Notesdocument

Stop

Set db = session.CurrentDatabase

Set v = db.GetView("Test")

Call v.refresh

Set doc = source.Document 

Set parent =db.getdocumentbyunid( doc.~$REF(0)  ) 



Set dc = v.GetAllDocumentsByKey(doc.~$REF(0), True ) 

If dc .count =0 And parent.mailflag(0) <> 1 Then

	

	Messagebox( "Hello" & dc.count)

	parent.mailflag =1

	Call parent.save(True,True)

End If

Where I have the messagebox “hello” is where I will put additional code, but that tells me if it works…

Hope it makes sense to you

Thanks again…I’m sure you will see more posts from me, as I’m new to Script and have nothing but trouble ‘looming’ ahead…lol

ccl

Subject: RE: Mary Anne, Here is my code:

Looks good! Glad it is working for you so far. You may run into a problem with dc.count = 0 because sometimes the collection is null, then you need an “If not dc is nothing” instead.

Subject: Mary Anne, thank you, this was a follow up to

a previous question that I had, that you answerd. The line of code that was giving me problems is :

Set LkupColl = view.GetAllDocumentsByKey( response.~$REF(0) )

Thank you I will try this now, as I look thru your code I have the feeling this will work or is much closer to working than what I currently have, thanks so much for taking the time to respond.

I’m new to script, I love it, but it is not intuitive to me, and am admittedly struggling but slowly getting there…

Thanks again,

Happy Holidays,

ccl

Subject: RE: Mary Anne, thank you, this was a follow up to

No problem, I’m glad to help! Just post your code if you need more help.

Subject: can someone point me to an example, please

Carl,

In the postsave event of your reponse document form, you basically need to do the following…

1 - get a handle on the parent document (NotesDocument.ParentDocumentUNID will help you get to this)

2 - build a collection of the parent document’s responses (NotesDocument.Responses)

3 - loop through each response document. If the status <> closed then exit the code

4 - If you made it to the end and all the documents had a status of closed, update the parent document and save

HTH

Mike

Subject: Thanks for the response, Mike, appreciate it!