Link to home
Start Free TrialLog in
Avatar of kspuea
kspuea

asked on

Detect whether a document is currently being opened?

Hi,
I have 3 forms,ie. parentdoc, firstchild, secondchild.
The firstchild doc & secondchild doc are response documents to the parentdoc.
In firstchild doc, I can get the unid of parentdoc, and detect that whether the parentdoc is currently opened (through IsUIDocOpen property).
However, I can't detect whether the secondchild doc is opened by using its unid.
Why? Is it because parentdoc is document, but secondchild doc is a reponse document, so I can detect whether it's opened?

Please enlighten me if you know.
Thanks in advance.
ASKER CERTIFIED SOLUTION
Avatar of Arunkumar
Arunkumar

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Arunkumar
Arunkumar

ok
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of kspuea

ASKER

Thanks, Arun & ghassan99!!

Actually, the seconddoc is not created thru coding, the seconddoc is an existing doc.
So, in firstdoc, before I'm trying to set some values in the seconddoc, I have to make sure that the seconddoc is not currently opened.

Here is my coding:
---------------------
Set seconddoc = view.GetDocumentByKey(firstdoc.ParentDocumentUNID, True)
If seconddoc.IsUIDocOpen Then
   Msgbox "Score cannot be saved. Please check that PIPEC is not currently being opened. If so, please close PIPEC and score this KRA again."
   Exit Sub
End If
----------------------
The "view" is sorted by the ParentDocumentUNID of the seconddocs.

In fact, we have implemented a "locking" method to the docs. And we are able to detect whether the doc is in editmode. But that doesn't cater for open docs.

Thanks again for you guys help! :-)
I havent tried this, but why dont you try and set an env var (or a field somewhere in the db, profile doc?) in the post open event.  So you can detect if the doc is open or not.  I'm not sure, but is this what you are suggesting hemanth?

-Gus
Yes something similar to that.

~Hemanth
Avatar of kspuea

ASKER

But I used the same approach to detect the Parentdoc, and it works.
Why? The only thing I can think of is Parentdoc is a document, but seconddoc is a response document.

But in the Notes Help, there isn't any indication that the IsUIDocOpen property can't be used for Response documents.

Anyway, I can't set environment variables here, we have some rules to follow. And we don't have db profile either.

Any other ways?
Hi kspuea,

Whats your Notes version?
Can you post the script you are using?

As far as I'm concerned, I dont think its a matter of form type (response, main, etc.).

Thanks,
-Gus
Avatar of kspuea

ASKER

Thanks very much, Gus!
OK, my Notes client version is 4.5.7, server is R5.0.5.
And I'm developing it using version 4.5.7.

Here is my scripts:
----------------------------------------------
Sub Click(Source As Button)
     Dim ws As New NotesUIWorkspace
     Dim session As New NotesSession
     Dim db As NotesDatabase
     Dim view As NotesView, viewPL As NotesView
     Dim uidoc As NotesUIDocument
     Dim Pipecdoc As NotesDocument, Childdoc As NotesDocument, PARdoc As NotesDocument, nPipedoc As NotesDocument, docPLScore As NotesDocument
     Dim i As Integer, Strkra, Success, flag, confirm As Integer, inputScore As String, Decplace As Integer
     Dim kraField As String, PLField As String, UIDField As String, ScoreField As String, WeightField As String, HidAuthorRole
     
     Set db = session.CurrentDatabase
     Set uidoc = ws.CurrentDocument
     Set Childdoc = uidoc.Document
     Set view = db.GetView("vPipecScoreRedo")
     Set viewPL = db.GetView("PLScores")
     
     flag = ws.DialogBox("KRAScore", True, True, "Scoring", Childdoc)
     If flag = 0 Then
          Msgbox "KRA is not scored yet.", 64, "Scoring"
          Exit Sub
     End If
     
     HidAuthorRole = Evaluate("@IsMember(""[HiddenAuthors]""; @UserRoles)")
     inputScore = Childdoc.tmpScore(0) & "." & Childdoc.ScorePoint(0)    
     If (session.EffectiveUserName = Childdoc.ROName(0) Or HidAuthorRole(0)=1) And (Childdoc.PLName(0) = "") Then

          'THIS LINE IS TO GET THE DOCUMENT THAT I WANT TO DETECT WHETHER IT'S OPENING CURRENTLY
          Set Pipecdoc = view.GetDocumentByKey(Childdoc.ParentDocumentUNID, True)

          If (Pipecdoc Is Nothing) Then           'If PIPEC doesn't exist, create a new PIPEC based on PAR
               Set PARdoc = db.GetDocumentByUNID(Childdoc.ParentDocumentUNID)
               Set nPipedoc = CreatePIPEC(PARdoc)
               nPipedoc.KRA1 = Childdoc.Kra(0)
               nPipedoc.UID1 = Childdoc.UniversalID
               nPipedoc.Weight1 = Childdoc.Weight(0)
               nPipedoc.Score1= Cdbl(inputScore)
               Success = nPipedoc.ComputeWithForm(False, False)
               Call nPipedoc.Save(True, False)
               Childdoc.ShowSelfAppraisal = "Y"
               Childdoc.ShowReview = "Y"
               Childdoc.DateScored = Today()
               Call Childdoc.RemoveItem("tmpScore")
               Call Childdoc.RemoveItem("ScorePoint")
               Success = Childdoc.ComputeWithForm(False, False)
               Call uidoc.Save
               Call uidoc.Close
          Else
               If Pipecdoc.Hasitem("EditFlag") Then    'If someone updating the PIPEC doc
                    Msgbox "Score cannot be saved. Please check that PIPEC is not currently being edited. If so, please close PIPEC and score this KRA again."
                    Call Childdoc.RemoveItem("tmpScore")
                    Call Childdoc.Save(False, False)
                    Exit Sub
               'HERE IS THE PART I CHECK FOR THE DOCUMENT WHETHER IS OPENING
               Elseif Pipecdoc.IsUIDocOpen Then
                    Msgbox "Score cannot be saved. Please check that PIPEC is not currently being opened. If so, please close PIPEC and score this KRA again."
                    Call Childdoc.RemoveItem("tmpScore")
                    Call Childdoc.Save(False, False)
                    Exit Sub

               Else   'Nobody updating/opening PIPEC now
                    Dim PLitem As NotesItem, Kraitem As NotesItem, UIDitem As NotesItem, Scoreitem As NotesItem, Weightitem As NotesItem, uidfound As Integer
                    uidfound = 0
                    For i = 1 To 8    'To check whether the KRA has been scored before -- exceptional cases
                         Strkra = Pipecdoc.GetItemValue("UID" & Cstr(i))
                         If Strkra(0) <> "" Then
                              If Strkra(0) = Cstr(Childdoc.UniversalID) Then
                                   uidfound = 1
                              End If
                         End If
                    Next
                    If uidfound = 1 Then
                         Msgbox "The score of this KRA already exists in the PIPEC. Please contact HR immediately."
                         Call Childdoc.RemoveItem("tmpScore")
                         Call Childdoc.Save(False, False)
                         Exit Sub
                    Else
                         For i = 1 To 8
                              Strkra = Pipecdoc.GetItemValue("UID" & Cstr(i))
                              If Strkra(0) = "" Then
                                   Set Kraitem = Pipecdoc.ReplaceItemValue("KRA" & Cstr(i), Childdoc.Kra(0))
                                   Set PLitem = Pipecdoc.ReplaceItemValue("PL" & Cstr(i), Childdoc.PLName(0))
                                   Set UIDitem = Pipecdoc.ReplaceItemValue("UID" & Cstr(i), Childdoc.UniversalID)
                                   Set Scoreitem = Pipecdoc.ReplaceItemValue("Score" & Cstr(i), Cdbl(inputScore))
                                   Set Weightitem = Pipecdoc.ReplaceItemValue("Weight" & Cstr(i), Childdoc.Weight(0))
                                   Exit For
                              End If
                         Next
                    End If
                    Success = Pipecdoc.ComputeWithForm(False, False)
                    Call Pipecdoc.Save(True, False)
                    Childdoc.ShowSelfAppraisal = "Y"
                    Childdoc.ShowReview = "Y"
                    Childdoc.DateScored = Today()
                    Call Childdoc.RemoveItem("tmpScore")
                    Call Childdoc.RemoveItem("ScorePoint")
                    Success = Childdoc.ComputeWithForm(False, False)
                    'Call Childdoc.Save(True, False)
                    Call uidoc.Save
                    Call uidoc.Close
               End If
          End If
     Elseif (session.EffectiveUserName = Childdoc.PLName(0) Or HidAuthorRole(0)=1) And (Childdoc.PLName(0) <> "") Then
          Dim sKey (1 To 2) As String
          sKey(1) = Childdoc.UniversalID
          sKey(2) = Childdoc.PLName(0)
          'Find PLScore doc first, if not found create a new one, & store PL score inside
          Set docPLScore = viewPL.GetDocumentByKey(sKey, True)
          If (docPLScore Is Nothing) Then
               Set docPLScore = New NotesDocument(db)
               docPLScore.Form = "PLScoreFm"
          End If
          Call docPLScore.MakeResponse(Childdoc)
          docPLScore.PLScore = Cdbl(inputScore)
          docPLScore.KRAUid = Childdoc.UniversalID
          docPLScore.PLName = Childdoc.PLName(0)
          docPLScore.ROName = Childdoc.ROName(0)
          docPLScore.COName = Childdoc.COName(0)
          docPLScore.HODName = Childdoc.HODName
          docPLScore.HOGName = Childdoc.HOGName
          Success = docPLScore.ComputeWithForm(False, False)
          Call docPLScore.Save(True, False)
          Childdoc.DatePLScored = Today()
          Call Childdoc.RemoveItem("tmpScore")
          Call Childdoc.RemoveItem("ScorePoint")
          Success = Childdoc.ComputeWithForm(False, False)
          Call uidoc.Save
          Call uidoc.Close
     End If
End Sub
--------------------------------------------------------
I use this codes in an Action button.
Another difference is, I'm using GetDocumentByUNID method to get parentdoc, but I'm using GetDocumentByKey method to get the PIPEC doc.
Avatar of Zvonko
kspuea,
No comment has been added lately (1121 days), so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area for this question:

RECOMMENDATION: split points between Arunkumar http:#100645 and ghassan99 http:#101823 and HemanthaKumar http:#103112

Please leave any comments here within next five days.

-- Please DO NOT accept this comment as an answer ! --

Thanks,

Zvonko
EE Cleanup Volunteer