Solved

Document Save Conflict

Posted on 2003-12-02
38
789 Views
Last Modified: 2013-12-18
I have a main form with a Save and Close button and a Create Details button. The Details form inherits docid in the main form. The user, after filling up the main form, clicks the Create Details button. (see below the code i placed in the buttons). The Details form will open, and the user will fill it up, during saving of the details form, it will change some of the fields in the main form so the user has to click the save and click button on the main form after saving the details form. Another thing, i also added a code in the post save of  the details form. When the user clicks the Save and Close button in the main form the following message appears "Another copy of this document was saved while you were editing it. Save your changes also as a save conflict document?"

This is kindda urgent guys. Hoping for your prompt reply. Thanks in advance! :)

Codes:

Save and Close button in Main Form:
@Command([EditDocument];"1") ;
@Command([ViewRefreshFields]) ;
@Command([FileSave]);
@Command([FileCloseWindow])

Create Detail Button in Main Form:
@Command([FileSave]);
@Command([Compose];"details")

Save and Close button in Details Form:
@SetDocField(maindocid;"lastupdate";cpdate);
tempo :=@GetDocField(maindocid; "ctimeo");
@If (tempo= "";@SetDocField(maindocid;"ctimeo";timeo);"");
@If(@Trim(status) = "CLOSED"; @SetDocField(maindocid;"closedtime";cpdate);"");
@Command([FileSave]);
@Command( [FileCloseWindow] )

Post Save event in Details Form:
Sub Postsave(Source As Notesuidocument)
      Dim w As New NotesUiWorkspace
      Dim s As New NotesSession      
      Dim dbCurrent As NotesDatabase
      Dim viewDailyColl As NotesView
      Dim entryDailyColl As NotesViewEntry
      Dim vc As NotesViewEntryCollection
      Dim docDailyColl As NotesDocument
      Dim docTMP As NotesuiDocument
      Dim m As String
      
      Set dbCurrent = s.CurrentDatabase
      Set docTMP = w.currentdocument
      
      m = docTMP.FieldGetText( "maindocid" )
      
      Set viewDailyColl = dbCurrent.getView("Status")
      Set vc = viewDailyColl.GetAllEntriesByKey(m)
      If vc.count = 0 Then
            Messagebox("Please create at least 1 detail of the case")
            Exit Sub
      End If
      
      For i = 1 To vc.count            
            
            Set entryDailyColl = vc.GetNthEntry(i)            
            Set docDailyColl = entryDailyColl.Document            
            docDailyColl.dstat = docTMP.FieldGetText( "status" )
            Call docDailyColl.Save(True,False)      
            
      Next
End Sub
0
Comment
Question by:macjacinto
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 18
  • 13
  • 3
  • +3
38 Comments
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 9857235
I assume you keep the main form open in edit-mode while details are filled in. I'd suggest to make the Details button visible only in read-mode, thus preventing multiple simultaneous updates on the main form. You can also put the document in read-mode when pressing the Details button. If you want to modify values on the main-form from the details-form, you can do that safely, but the info on the main-form on screen will not be changed until a reload.
0
 
LVL 13

Expert Comment

by:CRAK
ID: 9857957
Exactly!
Is there a way to make "dstat" computed for diaplay and let it show the value of "status" dynamically (using e.g. @DbLookup)?
(note that if a document already contains a field dstat, the computed for display result won't show; the available field will show instead!)
0
 
LVL 24

Expert Comment

by:HemanthaKumar
ID: 9861422
Instead of executing the script in PostSave, execute it in QuerySave.. This should prevent the conflicts.

~Hemanth
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 31

Expert Comment

by:qwaletee
ID: 9863295
Right now, you have the CREATE DETAILS button save the main document and create a detail doc.

Instead, have it save AND CLOSE the main document, so that it is not open at all.  Some others have suggested that yuo put teh main document in read mode.  That will sometimes be good enough.  But if the user siwtches the main docuemnt back to edit mdoe from read mode, the same conflict action will occur, because the "old state" of teh document is cahced even in red mode, and will not be refreshed when swicthin back to edit,  Because of that, the open window has the old doc information (before the details form modified it), and upon save, it will notice the conflict problem.

How to make this work?  Put the following code in CREATE DETAILS:
@PostedCommand([FileSave]);
@PostedCommand([Compose]; "details")
@PostedCommand([FileOpenDatabase]; @DbName; ""; "1");
@PostedCommand([OpenDocument]; "0"; @Text(@DocumentUniqueID));
@PostedCOmmand([FileCloseWIndow]);
@PostedCOmmand([FileCloseWIndow]);
0
 

Author Comment

by:macjacinto
ID: 9863665
sjef_bosman:

If i make the Details button visible in read-mode only, the user has to click the save and close first, then open the document again just to create a detail form? And also, how can put the main document in read mode when pressing the Details button?

crak:

Its possible to make dstat a computed for display field and get its value through dblookup..however, the main function of the post save code is to change all values of dstat in all details doc of one main document, you see, its possible that in one main doc, multiple details doc were created, and i used the docid of the main doc to keep tab of all the details of the said main doc. How will i then incorporate this function if i get the value through dblookup?

hemanth:

The message from the script appeared " Please create at least 1 detail of the case". I think this is because the document hasn't been saved yet bec as the definition of Query save in help - it "Occurs just before the current document is saved"

qwaletee:

The message "Server error: Entry not found in index" appeared


I'll provide additional points to whoever solves this problem today. Thanks!!
0
 
LVL 19

Expert Comment

by:madheeswar
ID: 9863804
let me guess what ur doing.

U r creating a main form and once saved, some of the data is fetched into a new form called details form.

In this details form, once its is saved, few data should be updated in the main form which was created before.

Am I correct or missing some thing?
0
 

Author Comment

by:macjacinto
ID: 9864506
yes madheeswar, that's correct. as ive' said in my first post, some of the fields in the details form are inherited from the main form
0
 
LVL 19

Expert Comment

by:madheeswar
ID: 9864538
Since what I said is correct, then I will expain my logic on how to complete this.

On ur main form, capture document unique id(say first 10 chars).
Inherit what ever the value u want into Details form, including unique id.

While u compose details form, close main form. Since we captured doc., unique  id, look for that document using L.Script and update the fields which ever u want.

If the logic is OK with u, I can provide solution by today itself.

waiting for ur reply.
0
 

Author Comment

by:macjacinto
ID: 9864684
the code as it is now can already capture the doc id of the main form and pass it to the details doc.

the logic is ok, i can try the solution u will be providing. tnx
0
 
LVL 19

Expert Comment

by:madheeswar
ID: 9864707
Button on Main form:
@Command([FileSave]);@Command([FileCloseWindow]);@PostedCommand([Compose];"DetailsForm")

Now, For save&Close in Detials Form:.

Sub Click(Source As Button)
      'http://oldlook.experts-exchange.com/Applications/Email/Lotus_Notes/Q_20813669.html
      Dim ws As New notesuiworkspace
      Dim uidoc As notesuidocument
      Dim curdoc As notesdocument
      
      Set uidoc=ws.currentdocument
      Set curdoc=uidoc.document
      
      Dim ss As New notessession
      Dim db As notesdatabase
      Dim view As notesview
      Dim dc As notesdocumentcollection
      Dim doc As notesdocument
      
      Set db=ss.currentdatabase
      Set view=db.getview("ViewNamehavingdocsofMainform")
      Dim tmpkey As String
      tmpkey=curdoc.UniquekeyFieldname(0)
      Set doc=view.getdocumentbykey(tmpkey,True)
      If Not doc Is Nothing Then
            doc.urfieldsto update=curdoc.fieldtoupload(0)
            'ur fields will follow
            Call doc.save(True,True)
      End If
      Call curdoc.save(True,True)
      Call uidoc.close
End Sub

Please let me know if it is working or not.
0
 
LVL 19

Expert Comment

by:madheeswar
ID: 9864736
the above works only to update main document created by main form.

So, each document created by main form will have unique id's.So, documents created using these unique id's will be updated.

if u r not clear what it does, let me know.

Please test it fast and let me know.
-Thanks.
0
 

Author Comment

by:macjacinto
ID: 9864851
upon save and close of the main form..the message "Field 'casenum' : Invalid UNID; UNID must be a 32-digit hex string. Field casenum in Details form is a computed field. It gets its value using the code @GetDocField(maindocid ; "casenum" )
0
 
LVL 19

Expert Comment

by:madheeswar
ID: 9864878
what is the code for maindocid?

U can use unique id or a part of unique id like:

@Left(uniqueid;10)
0
 

Author Comment

by:macjacinto
ID: 9864978
maindocid is computed when composed field. its value is docid. w/c is a field in main form. details form "formulas inherit values from selected document" option is enabled. docid field's code in main form is @DocumentUniqueID
0
 
LVL 19

Expert Comment

by:madheeswar
ID: 9865020
in the main form for maindocid is correct

for details form field casenum should be computedwhen composed. And the defualt value should be maindocid

this will automatically fetches values from mainform.

And test my code and let me know.

Note: for mainform doc's., first column should be sorted and the formula for column should be @text(maindocid)

and in my code change to
set doc=view.getdocumentbykey(cstr(tmkey),true)

do it fast and let me know as I will stay for another 2 hours.
0
 

Author Comment

by:macjacinto
ID: 9865067
maindocid field in details form is empty.

i changed the casenum's code to docid, and it turned out empty as well. also, the value of the casenum field in the details form should be the value of the casenum form in the main form, that's why i used the code @GetDocField(maindocid ; "casenum" )

when i clicked save and close, the message "do u want to save this form" appeared

and since i have a post save code in my details form, another message " object variable not set" appeared. when i debugged it, it stopped at the if vc.count = 0 line

gosh...things got a little complicated
0
 
LVL 19

Expert Comment

by:madheeswar
ID: 9865071
send me ur template to reddyatstoneforest.com.sg

0
 

Author Comment

by:macjacinto
ID: 9865276
ill send it now...thanks
0
 
LVL 19

Expert Comment

by:madheeswar
ID: 9865285
u have wasted one hour time.
I will stay another 45 mintutes. Within that time, if I solve it, I will send, else u need to wait till tomorrow.
0
 

Author Comment

by:macjacinto
ID: 9865303
i sent it to reddy@stoneforest.com.sg?...is that correct?
0
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 9865315
Goodness gracious me! What's wrong with the original solution? I wrote a second possibility: "You can also put the document in read-mode when pressing the Details button. ". See also the first comment of qwaletee. There's nothing wrong with the general direction of your original solution, so why investigation alternatives?
0
 
LVL 19

Expert Comment

by:madheeswar
ID: 9865319
i received it
0
 

Author Comment

by:macjacinto
ID: 9865338
i posted a comment after reading the suggestions u made, here it is again.

sjef_bosman:

If i make the Details button visible in read-mode only, the user has to click the save and close first, then open the document again just to create a detail form? And also, how can put the main document in read mode when pressing the Details button?

crak:

Its possible to make dstat a computed for display field and get its value through dblookup..however, the main function of the post save code is to change all values of dstat in all details doc of one main document, you see, its possible that in one main doc, multiple details doc were created, and i used the docid of the main doc to keep tab of all the details of the said main doc. How will i then incorporate this function if i get the value through dblookup?

hemanth:

The message from the script appeared " Please create at least 1 detail of the case". I think this is because the document hasn't been saved yet bec as the definition of Query save in help - it "Occurs just before the current document is saved"

qwaletee:

The message "Server error: Entry not found in index" appeared

0
 
LVL 19

Expert Comment

by:madheeswar
ID: 9865493
WHAT i FOUND TILL now is u have some bugs in ur save&close button in details form. So, paste this code instead of urs.
Sub Click(Source As Button)
      
      Dim ws As New notesuiworkspace
      Dim uidoc As notesuidocument
      Dim curdoc As notesdocument
      
      Set uidoc=ws.currentdocument
      Set curdoc=uidoc.document
      
      Dim ss As New notessession
      Dim db As notesdatabase
      Dim view As notesview
      Dim dc As notesdocumentcollection
      Dim doc As notesdocument
      
      Set db=ss.currentdatabase
      Set view=db.getview("MainDocs")
      Dim tmpkey As String
      tmpkey=curdoc.maindocid(0)
'      Set doc=view.getdocumentbykey(tmpkey,True)
      Set doc=view.getdocumentbykey(Cstr(tmpkey),True)
      If Not doc Is Nothing Then
            doc.lastupdate=curdoc.cpdate(0)
            If doc.ctimeo(0)= "" Then
                  doc.ctimeo=curdoc.timeo(0)      
            End If
            If curdoc.status (0) = "CLOSED" Then
                  doc.closedtime=curdoc.cpdate(0)      
            End If
            
          'ur fields will follow
            Call doc.save(True,True)
      End If
      Call curdoc.save(True,True)
      Call uidoc.close
      
End Sub

This should be working now. check it  and let us know.
0
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 9865520
That's what I responded to: use qwaletee's and my suggestion, so
- display Details all the time
- prevent the main document from being modified when you edit the details, i.e.
   - close the main document first before filling in the Details form
   - or reopen the main document in read-only mode (as qwaletee suggests)

A slightly modified copy of qwaletee's code (without permission from the original editor ;-):

The general idea is to put the following code in CREATE DETAILS:
@PostedCommand([FileSave]);
@PostedCommand([Compose]; "details")
@PostedCommand([FileCloseWindow]);

The two lines removed used to reopen the current document in read-only mode. You can alway put them back:
@PostedCommand([FileOpenDatabase]; @DbName; ""; "1");
@PostedCommand([OpenDocument]; "0"; @Text(@DocumentUniqueID));

0
 
LVL 19

Expert Comment

by:madheeswar
ID: 9871333
mac,
what is the result?
0
 

Author Comment

by:macjacinto
ID: 9872074
sjef_bosman:

i tried using the code w/o the last 2 lines but when i clicked the button, the details form did not appear and the current form (main form) was not closed

madhesswar:

i also tried the code u gave but m still having the same problem. can u just resend to me the database u already edited? my email address e macjacinto@yahoo.com



ill be waiting for your comments guys. thanks
0
 
LVL 19

Expert Comment

by:madheeswar
ID: 9872087
I have sent, check it
0
 
LVL 31

Accepted Solution

by:
qwaletee earned 200 total points
ID: 9872324
Instead of the formula, use the following script:

      Dim ws As New notesUiWorkspace
      Dim s As New notesSession
      Dim db As notesDatabase
      Set db = s.currentDatabase
      Dim oldDoc As notesUiDocument
      Set oldDoc = ws.currentDocument
      oldDoc.save
      Dim newDoc As notesUiDocument
      Set newDoc = ws.composeDocument (db.server , db.FilePath , "details")
      oldDoc.close
      
      
The reason I had the convoluted formula code was I wanted to:
1) compose new doc with old doc still open, otherwise, I might inherit off the wrong doc
2) close the old doc window

(1) is easily accomplished.  But in formula, how do you close the window that is NOT current?  So, I added some code that SHOULD open the same document again, and Notes is generally smart enough to try to re-use the existing window when opening a document that is already open in an existing widnow.  Obviously, I missed something.

But the script will do that properly, and its tested.
0
 
LVL 19

Expert Comment

by:madheeswar
ID: 9872331
Qwaletee,
I opened a question, please try to answer it.

-Thanks.
0
 

Author Comment

by:macjacinto
ID: 9872726
qwaletee:

i used the code u gave, it saved but i cant see it in my all cases view, (view selection "uses forms Details & New Cases"(New Cases is the main form))
0
 
LVL 19

Assisted Solution

by:madheeswar
madheeswar earned 300 total points
ID: 9872737
Change the code in details form to:
Sub Click(Source As Button)
      
      Dim ws As New notesuiworkspace
      Dim uidoc As notesuidocument
      Dim curdoc As notesdocument
      
      Set uidoc=ws.currentdocument
      Set curdoc=uidoc.document
      
      Dim ss As New notessession
      Dim db As notesdatabase
      Dim view As notesview
      Dim dc As notesdocumentcollection
      Dim doc As notesdocument
      
      Set db=ss.currentdatabase
      Set view=db.getview("MainDocs")
      Dim tmpkey As String
      tmpkey=curdoc.maindocid(0)
'      Set doc=view.getdocumentbykey(tmpkey,True)
      Set doc=view.getdocumentbykey(Cstr(tmpkey),True)
      If Not doc Is Nothing Then
            doc.lastupdate=curdoc.cpdate(0)
            If doc.ctimeo(0)= "" Then
                  doc.ctimeo=curdoc.timeo(0)      
            End If
            If curdoc.status (0) = "CLOSED" Then
                  doc.closedtime=curdoc.cpdate(0)      
            End If
            
          'ur fields will follow
            Call doc.save(True,True)
      End If
      'Call curdoc.save(True,True)
      Call uidoc.save
      Call uidoc.close
      'Call curdoc.close(True)
End Sub

Note: I have tested it and everything works fine.

In your allCases view, I think thier is a problem. In the mean time u check this code and let us know. As per ur requirement, its working perfectly.

And for the view, I will test it. and let u know.
0
 

Author Comment

by:macjacinto
ID: 9872757
what should be the value of casenum field in the details form?
0
 
LVL 19

Expert Comment

by:madheeswar
ID: 9872770
casenum. this field is fetched from new details form automatically.

U r view is corrupted. Just now I have created a new view with both forms included. Its working fine,

0
 
LVL 19

Expert Comment

by:madheeswar
ID: 9872803
I found the error. It is in the Resolution Time column. Once u remove it, it should be ok.
0
 

Author Comment

by:macjacinto
ID: 9872814
the maindocid and casenum's value in details form are still empty

can u pls send the dbase w/ not empty casenum?

ill wait. tnx
0
 
LVL 19

Expert Comment

by:madheeswar
ID: 9872815
@Return should not be used in column formulas.

The above is from help.

U have used @Return and that code looks like it has lots of bugs. What u want actually in that column?

This is becoming another question. Its better u post another question with the code which u have it in the column.

its not fair for me to solve without other experts approval as it is different problem from this question.

don't take it too personal.
0
 
LVL 19

Expert Comment

by:madheeswar
ID: 9872845
I have sent the db. Check it and let us know.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For Desktop Techs: How to retain a user's Notes configuration data when swapping out the end user's computer. (Assuming that you are not upgrading to a completely different version of Notes client) All you need to do is: 1) install Notes o…
You’ve got a lotus Domino web server, and you have been told that “leverage browser caching” is a must do. This means that we have to tell the browser everywhere in the web to use cache. In other words, we set (and send) an expiration date in the HT…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

705 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