How to handle writing to uidoc from dialog box?

What is the best way to handle this situation?

From a uidoc, a dialogbox is opened.

The dialogbox routine loops through a collection of backend documents and writes some data back. This includes the original open uidoc.

When I save the doc that is also open in the uidoc I, of course, get a save conflict warning.

I can’t figure out how (if possible) to get a handle on the original uidoc from the dialog box.

What is the best way to handle this?

Many thanks for any help on what I am sure is a simple question!

Subject: How to handle writing to uidoc from dialog box?

I guess I don’t follow what your issue is. If you are initiating a dialogbox in script from a form, you already have a handle to the current uidoc from the initiation point.

I proposed a solution that would work in a previous post. Like I said, set an environment variable to the UNID of the original UIDOC. Then you can get a handle to it from your dialogbox using a few methods such as GetDocumentByUNID to get the backend doc and then the front end doc using:

Set notesUIDocument = notesUIWorkspace.EditDocument(True,Doc)

Subject: How to handle writing to uidoc from dialog box?

In your dialogbox routine that does the looping, check to see if one of the docs you are processing is the same as the uidoc you have open.

You can set the UniversalID to an environment variable like so:

ENVIRONMENT OpenUIDoc := @DocumentUniqueID

Then, prior to your loop, get the environment var using:

notesSession.GetEnvironmentString(OpenUIDoc)

Then in your loop, check the doc.UniversalID to see if its the same doc, if it is, don’t update, else do your updating.

Subject: How to handle writing to uidoc from dialog box?

Make sure you have a computed text field docID with formula as @Text(@DocumentUniqueID), in all the documents of your loop. If you do not have one create a field and update it with an agent. Get the key(uidoc.FieldGetText(“DocID”) in your dialogbox action, into a variable. Compare it with documents in loop. When you get the ui backend document, save it this way,

if uidoc.FieldGetText(“docID”) = docInLoop.docID(0) then

uidoc.Document.Field1 = “A”

uidoc.Document.Field2 = “B”

Call uidoc.Document.Save(True, True)

Call uidoc.Refresh (Refresh uidoc with newly saved values)

else

docinLoop.Field1 = “A”

docInLoop.Field2 = “B”

Call docInLoop.Save(True, True) (Saves backend doc)

end if

Subject: RE: How to handle writing to uidoc from dialog box?

Thank you for your response. I am struggling with getting a handle on the uidoc from the dialog box.

I have tried using the editdocument method to bring with the newinstance=false flag. But, this not seem to work. I believe it fails because, with the dialogbox open, I can not change focus to any other uidoc.

Any ideas???

Subject: RE: How to handle writing to uidoc from dialog box?

Why do you want to get a handle of uidoc. In dialogbox, when you use uidoc, it will be the document in the dialogbbox but not the underlying document.

If you are trying to get the dociD, what you can do is, Have a “computed hidden field” → dlgDocId and in the script which is opening the dialog box, update this dlgdocid as:

dlgdoc.dlgdocID = uidoc.FieldGetText(“docID”) or

dlgdoc.dlgdocID = uidoc.Document.docID(0)

and then open the dialogbox. This way you don’t have to bother about the underlying uidoc when you open the dialog box. From Dialogbox, now you can get the docID from the field dlgdocID and use it to find if it exists in the loop.

Hope this gives you clear picture.