Home > Domino Tips > Developer > LotusScript > Preventing conflicts when updating parent from response
Domino Tips:
EMAIL THIS
 TIPS & NEWSLETTERS TOPICS 

LOTUSSCRIPT

Preventing conflicts when updating parent from response


Scott Hooks
07.24.2003
Rating: -4.50- (out of 5) Hall of fame tip of the month winner


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


I have an application where a response document updates fields in a parent document when it is first saved. The problem, as many of you may know, is that if the user creates the response document from the parent document, then edits and saves the parent document, a conflict occurs because the backend parent document has changed. The NotesUIDocument.reload method does not work in this situation.

I searched the common forums, but could not find any working solutions. Several suggested closing the parent first, but that is harder than it sounds for a variety of reasons. Finally, I came up with the code below, which does the trick and has lots of other little gems for this type of functionality.

Code

Create an action on the parent document to create the response document and only allow the response to be created through this action. Put the following code in the action (note that this does not actually create a document -- it only sets a flag that will be detected in the QueryClose event):

FIELD CreateResponse := 
CreateResponse;

@If(@IsDocBeingEdited; ""; 
@Command([EditDocument]));

@If(
 @IsValid;
 @Do(
  @SetField("CreateResponse"; "Y");
  @PostedCommand([FileSave]);
  @PostedCommand([FileCloseWindow])
 );
"");
Then place the following code in the QueryClose event of the parent form, which will create the response when the parent is closed:

Sub Queryclose(Source As 
Notesuidocument, Continue As Variant)
 
 Dim uiwork As New notesuiworkspace 
 Dim doc As NotesDocument
 Set doc = source.Document
 
 If source.EditMode Then
  'Reload to be sure to get the flag
  'Not sure if this is necessary
  Call Source.Reload
 End If
 
 If doc.CreateResponse(0) = "Y" Then
  Call uiwork.ComposeDocument
( "", "", "Response" )
  'Clear the flag so it doesn't do it 
the next time the document is closed.
  doc.CreateResponse = ""
  Call doc.Save( False, False )
 End If
 
End Sub
If you want to reopen the parent when the response is saved (so the user never really knows it was closed), you can add the following code to the QuerySave and QueryClose events in the response document:

Sub Querysave(Source As 
Notesuidocument, Continue 
As Variant)
  'Open parent in edit mode
  If source.IsNewDoc Then
   doc.GetParent = "Y"
  Else
   doc.GetParent = ""
  End If
End Sub


Sub Queryclose(Source As 
Notesuidocument, Continue 
As Variant)
 Dim session As New notessession
 Dim db As notesdatabase
 Dim uiwork As New notesuiworkspace  
 Dim uidoc As NotesUIDocument
 Dim doc As NotesDocument 
 Dim parent As notesdocument 
 
 Set doc = Source.Document
 Set db = session.CurrentDatabase
 
 If doc.GetParent(0) = "Y" Then
  Set parent = db.GetDocumentByUNID
( doc.ParentDocumentUNID )
  If Not (parent Is Nothing) Then
   Set uidoc = uiwork.EditDocument
( False, parent )
  End If
  doc.GetParent = ""
  Call doc.Save( False, False )
 End If
End Sub

Do you have comments on this tip? Let us know.


Rate this Tip
To rate tips, you must be a member of SearchDomino.com.
Register now to start rating these tips. Log in if you are already a member.


Submit a Tip




Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


RELATED CONTENT
LotusScript
Create a non-specified date picker with LotusScript code
LotusScript accesses clipboard to view copied Notes documents
LotusScript action button manages Lotus Notes mail files
LotusScript sorts a Lotus Notes document collection
Display Lotus Notes user group membership details in a tree view
Alternate version of @Command forwards subform via LotusScript
Process large arrays in Notes forms without undue coding or testing
How to use LotusScript to modify a Lotus Notes view selection
Display a custom message box using a LotusScript-generated button
Debug Lotus Notes documents using extracted data

LotusScript
Customize the principal field of outgoing email messages
Create a non-specified date picker with LotusScript code
Resolve Notes 8 migration error: 'Database has not been opened yet'
LotusScript accesses clipboard to view copied Notes documents
LotusScript action button manages Lotus Notes mail files
LotusScript sorts a Lotus Notes document collection
Display Lotus Notes user group membership details in a tree view
Alternate version of @Command forwards subform via LotusScript
Process large arrays in Notes forms without undue coding or testing
How to use LotusScript to modify a Lotus Notes view selection

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary

DISCLAIMER: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.



Domino & Lotus Notes Security Solutions: Authentication, Antispam, Encryption and Antivirus
HomeTopicsITKnowledge ExchangeTipsAsk the ExpertsMultimediaWhite PapersDomino IT Downloads
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides enterprise IT professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective IT purchase decisions and managing their organizations' IT projects - with its network of technology-specific Web sites, events and magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Reprints  |  Site Map




All Rights Reserved, Copyright 1999 - 2008, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts