Solved

Get all response docs via LS

Posted on 2002-06-14
8
302 Views
Last Modified: 2013-12-18
I have got a main form and response as well as resp to resp docs being created.there can be n number of branches of resp to resp docs.Now there is an action in resp to resp docs called Close.
My objective is when i click on Close it should check whether all other resp to resp docs created out of the resp doc have been closed by checking a status field which is set to closed.
Now if all the resp to resp docs are closed then the resp doc will also be set to closed else it will not be closed.

This has to be done using Lotus Script
Any solution??
0
Comment
Question by:sampa
  • 5
  • 2
8 Comments
 
LVL 24

Expert Comment

by:HemanthaKumar
ID: 7078660
Here is the script which runs through the responses and matches the count to see if everything has the status closed, if so it will advance or it will prompt you an error

     Dim ws As New NotesUIWOrkspace
     Dim uidoc As NotesUIDOcument
     Dim note As NotesDocument
     Dim s As New NotesSession
     Dim db As NotesDatabase
     Dim doc As NotesDocument
     Dim col As NotesDocumentCollection
     Count = 1        ' Excludes this document
     Set db = s.CurrentDatabase
     Set uidoc = ws.CurrentDocument
     Set note = uidoc.Document
     Set doc = db.GetDocumentByUNID( note.ParentDocumentUNID)
     Set col = doc.Responses
     Set doc = col.GetFirstDocument
     While Not doc Is Nothing
          If doc.Status(0) = "Closed" Then
               Count = Count + 1
          End If
          Set doc = col.GetNextDocument(doc)
     Wend
     If Count <> col.Count Then
          Msgbox "Cannot Advance the status to closed", 16 , "Error"
     Else
          ' Set the Closed status
     End If
     

~Hemanth
0
 

Author Comment

by:sampa
ID: 7080112
Hemanth i have got n number of branches.See if i have a response doc say note and then n number of resp to resp might have been created for example remark.Now to this remark there have been again remarks added.
so it is like this
note
|
|
Remark1  remark2
|        |
remark3  remark4

and so on
Now if i close remark 3 i have got it's parent doc id in my form so i can go to note and get it's corresponding responses doc.Responses-which gives me remarks at the level of remark1 but what about corresponding levels

When remark3 is closed i want to check the status of all other remarks and if all of them are closed then automatically close the note.
0
 
LVL 10

Expert Comment

by:zvonko
ID: 7082514
Try this solution as Document Action:
Sub Click(Source As Button)
  Dim ws As New NotesUIWorkspace
  Dim session As New NotesSession
  Dim db As NotesDatabase
  Dim view As NotesView
  Dim entry As NotesViewEntry
  Dim descent As NotesViewEntry
  Dim nav As NotesViewNavigator
  Dim doc As NotesDocument
  Dim allClosed As Integer
  Set db = session.CurrentDatabase
  'enter below your hierachical view name
  Set view = db.GetView("Branch")
  Set nav = view.CreateViewNav
  Set doc = ws.CurrentDocument.Document
  Set entry = nav.GetEntry(doc)
  If (doc.Status(0) = "Closed") Then
    Print "Doc was Closed"
  Else
    allClosed = True
    If (entry.ChildCount > 0) Then
      Set descent = nav.GetNext(entry)
      Do While (descent.IndentLevel > entry.IndentLevel)
        If (descent.Document.Status(0) <> "Closed") Then
          Msgbox "Close first Doc at Pos: " & descent.GetPosition("."), 0, "Not Closing"
          allClosed = False
        End If  
        Set descent = nav.GetNext(descent)
        If (descent Is Nothing) Then Exit Do
      Loop
    End If
    If (allClosed = True) Then
      doc.Status = "Closed"
      Call doc.Save(True, False)
      Print "Doc Closed at Pos: " & entry.GetPosition(".")
      Call ws.CurrentDocument.Close
      Call ws.ViewRefresh
    End If
  End If
End Sub
====================================


or this one as View Action:
Sub Click(Source As Button)
  Dim ws As New NotesUIWorkspace
  Dim session As New NotesSession
  Dim db As NotesDatabase
  Dim view As NotesView
  Dim entry As NotesViewEntry
  Dim descent As NotesViewEntry
  Dim nav As NotesViewNavigator
  Dim dc As NotesDocumentCollection
  Dim doc As NotesDocument
  Dim allClosed As Integer
  Set db = session.CurrentDatabase
  Set view = ws.CurrentView.View
  Set nav = view.CreateViewNav
  Set dc = db.UnprocessedDocuments
  Set doc = dc.GetFirstDocument
  While Not (doc Is Nothing)
    Set entry = nav.GetEntry(doc)
    If (doc.Status(0) = "Closed") Then
      Print "Doc was Closed at Pos: " & entry.GetPosition(".")
    Else
      allClosed = True
      If (entry.ChildCount > 0) Then
        Set descent = nav.GetNext(entry)
        Do While (descent.IndentLevel > entry.IndentLevel)
          If (descent.Document.Status(0) <> "Closed") Then
            Msgbox "Close first Doc at Pos: " & descent.GetPosition("."), 0, "Not Closing"
            allClosed = False
          End If  
          Set descent = nav.GetNext(descent)
          If (descent Is Nothing) Then Exit Do
        Loop
      End If
      If (allClosed = True) Then
        doc.Status = "Closed"
        Call doc.Save(True, False)
        Print "Doc Closed at Pos: " & entry.GetPosition(".")
      End If
    End If
    Set doc = dc.GetNextDocument(doc)
  Wend
  Call ws.ViewRefresh
End Sub

And tell me how it works for you.

So long,
zvonko

0
 
LVL 10

Accepted Solution

by:
zvonko earned 100 total points
ID: 7082966
There is also a more elegant version of upper code.

Here as Document Action:
Sub Click(Source As Button)
  Dim ws As New NotesUIWorkspace
  Dim doc As NotesDocument
  Dim allClosed As Integer
  Set doc = ws.CurrentDocument.Document
  If (doc.Status(0) = "Closed") Then
    Print "Doc was Closed"
  Else
    allClosed = True
    Call CheckAllResponses( doc, allClosed)
    If (allClosed = True) Then
      doc.Status = "Closed"
      Call doc.Save(True, False)
      Print "Doc Closed "
      Call ws.CurrentDocument.Close
      Call ws.ViewRefresh
    End If
  End If
End Sub
Sub CheckAllResponses( doc As NotesDocument, isClosed As Integer )
  Dim collection As NotesDocumentCollection
  Dim currentResponse As NotesDocument
  Set collection = doc.Responses
  Set currentResponse = collection.GetFirstDocument
  While Not ( currentResponse Is Nothing )
    If (currentResponse.Status(0) = "Closed") Then
      Call CheckAllResponses( currentResponse, isClosed )
    Else
      Msgbox "One child not closed"
      isClosed = False  
    End If
    Set currentResponse = collection.GetNextDocument( currentResponse )
  Wend
End Sub
=========================================


or here as View Action:
Sub Click(Source As Button)
  Dim ws As New NotesUIWorkspace
  Dim session As New NotesSession
  Dim db As NotesDatabase
  Dim dc As NotesDocumentCollection
  Dim doc As NotesDocument
  Dim allClosed As Integer
  Set db = session.CurrentDatabase
  Set dc = db.UnprocessedDocuments
  Set doc = dc.GetFirstDocument
  While Not (doc Is Nothing)
    If (doc.Status(0) = "Closed") Then
      Print "Doc was Closed"
    Else
      allClosed = True
      Call CheckAllResponses( doc, allClosed)
      If (allClosed = True) Then
        doc.Status = "Closed"
        Call doc.Save(True, False)
        Print "Doc Closed "
      End If
    End If
    Set doc = dc.GetNextDocument(doc)
  Wend
  Call ws.ViewRefresh
End Sub
Sub CheckAllResponses( doc As NotesDocument, isClosed As Integer )
  Dim collection As NotesDocumentCollection
  Dim currentResponse As NotesDocument
  Set collection = doc.Responses
  Set currentResponse = collection.GetFirstDocument
  While Not ( currentResponse Is Nothing )
    If (currentResponse.Status(0) = "Closed") Then
      Call CheckAllResponses( currentResponse, isClosed )
    Else
      Msgbox "One child not closed"
      isClosed = False  
    End If
    Set currentResponse = collection.GetNextDocument( currentResponse )
  Wend
End Sub

The function CheckAllResponses is same code for both Actions. This function is recursive and therefore I hesitated to use it. But you have to use it if some of using clients are not R5, because NotesViewNavigator from my first version was invented in R5.

Good luck,
zvonko

0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 10

Expert Comment

by:zvonko
ID: 7100127
Hello samap,

you made no feedback so I ask you about the inconsistency between your question and the comment to Heman.

In your question you asked for:
"...if all the resp to resp docs are closed then the resp doc will also be set to closed.."

In comment to Heman you asked for:
"...automatically close the (main) note"

So what now? Are you asking for closing the main note or are you asking for closing of a head note in a brunch of ResponsesToResponses?

To bring both request together you can use my approach by using the parent document of a Response document as the starting node for the check.

But confirm first that this assumption is that what you are asking for.

So long,
zvonko

0
 
LVL 10

Expert Comment

by:zvonko
ID: 7112897
Hello...

0
 

Author Comment

by:sampa
ID: 7115937
Sorry about not responding coz I was away for sometime.I am sorry about the inconsistency.What i actually want is if to reach the end of each branch of response to response docs and find whether it is closed and if it is then check whether all other branches are closed.If all of them are closed then close the response or root doc.

Actually I have used the recursive function concept and tracked for open instead of closed coz if it finds at least one branch open then the root cannot be closed.
Thanks zvonko
0
 
LVL 10

Expert Comment

by:zvonko
ID: 7116863
Happy I could help :)

But what about my points now?

And please give me an A+ <|:-)

0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

I thought it will be a good idea to make a post as it will help in case someone else faces these issues. I trust this gives an idea how each entry in Notes.ini can mean a lot for the Domino Server to be functioning properly. This article discusses t…
  In today’s Arena we can’t imagine our lives without Internet as we are highly used to of it. If we consider our life style just for only 2 min we found that face to face communication is swapped by e-communication.  Every Where from Works place to…
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.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

760 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

21 Experts available now in Live!

Get 1:1 Help Now