• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 254
  • Last Modified:

Domino R5 web When editing Parent form, how can the status field in children be updated?

I have a parent form.  It is for users to fill in their project details.  The children are line items to store the requirements.  What i need is when I update and change the status on the Parent doc, I need an agent that will update the Status field in the children.   How would I write this agent?  I have moderate knowledge of Domino.  
0
a98pelle-expert
Asked:
a98pelle-expert
  • 5
  • 3
  • 2
1 Solution
 
a98pelle-expertAuthor Commented:
When I am saving the parent, I want the status field in the children documents to be updated.
0
 
Bill-HansonCommented:
Use a WebQuerySave agent to update the child documents.  This example assumes that the child documents are stored as responses to the main document.

To do this:

(1) Create a LotusScript agent and add the code below to the Initialize event.  Save it as "ProjectWebQuerySave".  Make sure that the agent trigger is On Event - Agent List Selection and the target is None.

(2) In your project form, select the WebQuerySave module and change it's value to:
@Command([ToolsRunMacro]; "ProjectWebQuerySave");
	Dim sess As New NotesSession
	Dim doc As NotesDocument
	Dim dc As NotesDocumentCollection
	Set doc = sess.DocumentContext
	Set dc = doc.Responses
	Call dc.StampAll("Status", doc.GetItemValue("Status")(0))

Open in new window

0
 
Sjef BosmanGroupware ConsultantCommented:
Not criticizing:
- I dislike StampAll, I've seen it fail on many occasions (does it exits in R5?)
- I don't know what the results are if there are no response documents
- response-to-response documents aren't stamped

Alternative code that might help (extracted, UpdateDoc should set the new status and sav the document):
Function UpdateDocs(dc As NotesDocumentCollection)
	Dim sdoc As NotesDocument
	Dim n As Integer
 
	UpdateDocs= 0
	If dc Is Nothing Then Exit Function
	Set sdoc= dc.getfirstdocument
	Do Until sdoc Is Nothing
		If Not sdoc.isdeleted Then
			n= n + UpdateDoc(sdoc)
			n= n + UpdateDocs(sdoc.responses)
		End If
		Set sdoc= dc.getnextdocument(sdoc)
	Loop
	UpdateDocs= n
End Function

Open in new window

0
[Webinar] Kill tickets & tabs using PowerShell

Are you tired of cycling through the same browser tabs everyday to close the same repetitive tickets? In this webinar JumpCloud will show how you can leverage RESTful APIs to build your own PowerShell modules to kill tickets & tabs using the PowerShell command Invoke-RestMethod.

 
a98pelle-expertAuthor Commented:
For 1) I did "Create", "Agent" and stored the code in the agent.  Named the agent "ProjectWebQuerySave".  I don't understand the second part where you say "Make sure the agent trigger is ON EVENT.."  Is that in the actual Parent form?
What-I-have.doc
0
 
a98pelle-expertAuthor Commented:
Bill: I tried your way and it does seem to work.  But my concern is if there are no responses...
0
 
a98pelle-expertAuthor Commented:
Sjef,  If I did your code...then how does it know which one is the Status field...In the Parent, the status field is named AI_Status...So in the cihld response form, I also have the same field name.  Where in your code do I put the status field...??
0
 
Bill-HansonCommented:
To check for responses, just check if doc.Responses is Nothing.
        Dim sess As New NotesSession
        Dim doc As NotesDocument
        Dim dc As NotesDocumentCollection
        Set doc = sess.DocumentContext
        If (doc.Responses Is Nothing) Then Exit Sub
        Set dc = doc.Responses
        Call dc.StampAll("Status", doc.GetItemValue("Status")(0))

Open in new window

0
 
Bill-HansonCommented:
FYI:

Regarding Sjef's code: it is just a framework for getting to all response documents regardless of how may levels of response documents there are.  To make the function useful, you would need to modify it.  You would only need to do so if you have more than one level of response documents to your project document.

Here's an example of an extension to that function is basically the same as NotesDocumentCollection.StampAll, except it will also set the field value on all responses to responses.

Using this function, your agent could become:

Sub Initialize
      
      Dim sess As New NotesSession
      Dim doc As NotesDocument
      Set doc = sess.DocumentContext
      Call UpdateAllResponses(doc, "Status", doc.GetItemValue("Status")(0))
      
End Sub
Function UpdateAllResponses(source As Variant, Byval item As String, value As Variant) As Long
	
	'/**
	' * Updates a field on all response documents.
	' * @param source A NotesDocument or NotesDocumentCollection containing the response documents.
	' * @return The number of documents that were updated.
	' */
	
	Dim doc As NotesDocument
	Dim dc As NotesDocumentCollection
	Dim count As Long
	UpdateAllResponses = 0
	Select Case Typename(source)
	Case "NOTESDOCUMENT"
		Set dc = source.Responses
	Case "NOTESDOCUMENTCOLLECTION"
		Set dc = source
	End Select
	If (dc Is Nothing) Then Exit Function
	Set doc= dc.GetFirstDocument
	Do Until (doc Is Nothing)
		If (Not doc.IsDeleted) Then
			Call doc.ReplaceItemValue(item, value)
			Call doc.Save(True, False)
			count = count + 1
			count = count + UpdateAllResponses(doc.Responses, item,  value)
		End If
		Set doc = dc.GetNextDocument(doc)
	Loop
	UpdateAllResponses = count
	
End Function

Open in new window

0
 
a98pelle-expertAuthor Commented:
Thanks.  I really appreciate it.   I will only have one level of responses after the parent.  
0
 
Sjef BosmanGroupware ConsultantCommented:
:-) One more problem solved. Nice code by the way!
0

Featured Post

Take Control of Web Hosting For Your Clients

As a web developer or IT admin, successfully managing multiple client accounts can be challenging. In this webinar we will look at the tools provided by Media Temple and Plesk to make managing your clients’ hosting easier.

  • 5
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now