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
LotusScript agent parses ACL to Microsoft Notepad
LotusScript finds the first occurrence of a string from the right
Clear Recent Contacts view and prevent repopulation in Lotus Notes 8.x
Search Microsoft Active Directory with LotusScript
Three steps to trap and handle save conflicts with LotusScript
Troubleshoot agents by displaying LotusScript variables online
LotusScript sorts lists alphabetically
LotusScript code rebuilds corrupted busytime.nsf file
Soft-code item names to facilitate LotusScript management
LotusScript agent automates selective mail file replication

LotusScript
LotusScript agent parses ACL to Microsoft Notepad
LotusScript finds the first occurrence of a string from the right
Clear Recent Contacts view and prevent repopulation in Lotus Notes 8.x
Search Microsoft Active Directory with LotusScript
Three steps to trap and handle save conflicts with LotusScript
Troubleshoot agents by displaying LotusScript variables online
LotusScript sorts lists alphabetically
Run or restart Notes/Domino agents via text messages
LotusScript code rebuilds corrupted busytime.nsf file
Soft-code item names to facilitate LotusScript management

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 technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations' technology projects - with its network of technology-specific websites, events and online magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Site Map




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