Locking Document & Web (Need Help)

I have posted this before… done additional research and no luck. I just feel like this is something simple (just not for me… lol). Here is the link to all my attempts… hoping this will also assist someone else.

note: I am just trying to (using onload, etc…) set a field to “locked” once someone edits. IOW… the doc would open in edit mode and save the lockstatus field -w- the “locked” value. I can handle the exit… user clicks save button or changes status (also buttons) and it changes the field back to unlocked. I am hiding subforms -w- buttons that allow users to edit based on lockstatus value. I know that a savvy user could use the ?edit document. You must understand our users… most are 60-80 years old and could care less about technology in general. Nothing against 60-80 year olds… because I know some techno-savvy ones in that range (just not our users)! I just want o accomplish the above… is causing issues with replication/save (as expected) conflicts on the web. A little reward… I will send a gift certificate (you name favorite online retailer) if you help me solve this! Please team… this is driving me bonkers. Thx…

http://www-10.lotus.com/ldd/nd6forum.nsf/ShowMyTopicsAllFlatweb/75daa0058836327d8525726d001f28f3?OpenDocument

Subject: Locking Document & Web (Need Help)

What I have done is as follows:Edit button trigers an agent that sets the “Locked” status to Locked and saves the doc. Then the agent opens the document in edit mode.

The save button sets “Locked” status to Open. Simple so far.

When a user opens the document in read mode, it does a lookup to a view of all Locked documents, and if it finds itself there it simply hides the Edit button.

I also have a Check Status button that does the lookup again if the document is already locked, and if it has since been unlocked by the other user, it reloads the page, and thus showing the edit button.

Subject: RE: Locking Document & Web (Need Help)

I created this “(savelock)” agent using the formula language. When the edit button is clicked, I get the following error:

Sorry, the requested page has been removed or incorrectly linked. HTTP Web Server: Lotus Notes Exception - @Function is not valid in this context

Here’s my formula… am using @Command([RunAgent]; “(savelock)”) behind the button.

@Command([EditDocument]); @SetField(“tmpLockStatus”; “Locked”); @SetField(“WhoLocked”; @Name([CN];@UserName)); @Command([FileSave]);@Command([EditDocument])

***am I needing to open a certain way… with docID?

Subject: RE: Locking Document & Web (Need Help)

I must be misinterpreting your suggestion re: webqueryopen. Am having no success using a WQO to place into edit then set fields… seems simple but not working. I would need to place into edit using the WQO, right? …otherwise, the “locked” status would be set when user is presented doc in read mode. …or maybe @SetField is not allowed in read mode. Any ideas? Thanks team…

Subject: Locking Document & Web (Need Help)

Hi Michael,Are you open to create lock stubs in the database, instead of storing lock status in the document that’s opened for editing?

It’s not so simple, as you think. I did it with use of Prototype.js, AJAX and lock documents.

Adibabu

Subject: RE: Locking Document & Web (Need Help)

Thanks to all… I will try the edit button + agent. Sounds simple enough… guess I was too focused on the document open handling this.

Would a simple ToolsRunMacro or RunAgent formula work? What would be in the agent? Would you use a URL to set value? …I thought I had tried @URLOpen(“/test/test.nsf/0/?editdocument&lockstatus=locked”) then a filesave. Is this a correct approach? …and would there need to be the same URLOpen -w- …?editdocument minus the &lockstatus-locked after the filesave to reopen?

note: I am interested in different approaches. Do you have any additional instructions re: the prototype.js (AJAX) option?

Subject: Locking Document & Web (Need Help)

You are looking way to hard at this. The solution is really simple.Have a computed for display field on your form that does the lookup to the islocked view. If it finds itself there set to 1 else set to 0. Your hidewhen for the edit button then simply uses this field for its formula.

Next, the locking agent:

When you hit the edit button, it calls the agent using

@Command( [ToolsRunMacro] ; “lockingagent” )

In this agent, the first thing it should dod is a lookup to this same doc and if it finds islocked = locked then it should goto the document in read mode again. If it does not find that it is locked, set the locked field to Locked and open in edit mode.

Dont overthink this.

Subject: RE: Locking Document & Web (Need Help)

Thanks… am trying to keep it “simple.” :slight_smile: A couple questions…

re: computed for display field… is it an @Dblookup to a view that uses view selection formula (islocked=locked). I’m assuming a key would need to be @DocUniqueID since there could be many docs with islocked=locked. Am I on track here? I’ll be honest… am a little confused about what formula/script you are using to determine the value of “if it finds itself there.”

Next step… the hide/when formula would be based on the islocked field value. e.g. hide paragraph when: islocked=“locked”. I have been doing this… must have been missing the view step.

I have tried the edit button -w- agent… mine was a simple @formula (@SetField(“islocked”; “locked”); @Command([EditDocument]). I had a filesave after the @SetField… required, right? …or else the doc would not be “locked” or show up in that view as locked.

Your assistance is appreciated… just need a bit more information re: formulas to make the view lookup work + the edit button formula. Thanks…

Subject: RE: Locking Document & Web (Need Help)

The computed for display field: Use a @Dblookup to the islocked view, using @Text(@DoctUniqueID) as the key. @If(@IsError(thedblookup);“Open”;“Locked”).The islocked view: View selection formula is islocked=locked.

The first column must be sorted ascending on @Text(@DocUniqueID).

As for the edit button, the hide when whould be when computed for display field is = “Locked”.

he edit button calls the agent.

Thge agent I used was a lotusscript agent. First i set doc to the session.documentcontext. Using doc I get the UNID . I then do a Set doc2 = dbCurrent.GetDocumentByUNID( UNID )

This way, if the doc was opened by 2 users at the same time, it will be using the latest version (ie whichever users version was edited first). I then check doc2.islocked(0) to see if it has been set to Locked by another user. If not, set doc2.islocked = “Locked”, call doc2.Save(true, true). Then open the doc2 in edit mode. (Print(“[” + db.filepath+“/0/”+doc2.UniversalID+“?EditDocument]”)

Else, if islocked = Locked, then someone has beaten you to the punch, so simply open the doc2 in readmode. (Print(“[” + db.filepath+“/0/”+doc2.UniversalID+“?OpenDocument]”).

Does that help?

Subject: RE: Locking Document & Web (Need Help)

OK… some comments/questions:

The computed for display field: Use a @Dblookup to the islocked view, using @Text(@DoctUniqueID) as the key. @If(@IsError(thedblookup);“Open”;“Locked”).

note: this makes perfect sense to me

The islocked view: View selection formula is islocked=locked.

The first column must be sorted ascending on @Text(@DocUniqueID).

note: this also makes sense

As for the edit button, the hide when whould be when computed for display field is = “Locked”.

note: ok… I was using computed vs. CFD. Will adjust…

The edit button calls the agent.

Thge agent I used was a lotusscript agent. First i set doc to the session.documentcontext. Using doc I get the UNID . I then do a Set doc2 = dbCurrent.GetDocumentByUNID( UNID )

This way, if the doc was opened by 2 users at the same time, it will be using the latest version (ie whichever users version was edited first). I then check doc2.islocked(0) to see if it has been set to Locked by another user. If not, set doc2.islocked = “Locked”, call doc2.Save(true, true). Then open the doc2 in edit mode. (Print(“[” + db.filepath+“/0/”+doc2.UniversalID+“?EditDocument]”)

Else, if islocked = Locked, then someone has beaten you to the punch, so simply open the doc2 in readmode. (Print(“[” + db.filepath+“/0/”+doc2.UniversalID+“?OpenDocument]”).

note: can you post (or send to dominoadmin@hotmail.com) the entire script? I understand the pieces you mentioned but don’t want to miss any lines.

Subject: Locking Document & Web - Agent Code

Sub Initialize Dim session As New NotesSession

Dim db As NotesDatabase

Dim doc As NotesDocument

Dim doc2 As NotesDocument

Dim username As String

Dim curruser As Variant



On Error Goto whoops



Set db = session.CurrentDatabase

Set doc = session.DocumentContext

curruser = Evaluate({ @Name([CN];@UserName) }, doc)

username = curruser(0)



'following step is done because the user could have opened the doc and only hit the edit button a few minutes later

'by which time another user could have opened and edited/locked the same doc

Set doc2 = db.GetDocumentByUNID(doc.UniversalID)



If Not doc2 Is Nothing Then

	If doc2.HasItem( "isLocked" ) Then

		If doc2.isLocked(0) = "Locked" Then

			If doc2.HasItem( "WhoLocked") Then

				If doc2.WhoLocked(0) = curruser Then

					'open in edit mode

					'the person who locked it is trying to edit it, so allow this

					Print("[" + db.filepath+"/0/"+doc2.UniversalID+"?EditDocument]")

				Else

					'open in read mode

					'the person other than the person who locked it is trying to edit it, so do not allow this

					Print("[" + db.filepath+"/0/"+doc2.UniversalID+"?OpenDocument]")

				End If

			Else

				'open in read mode

				'system problem as there is no person assigned to the WhoLocked field, so do not allow this

				Print("[" + db.filepath+"/0/"+doc2.UniversalID+"?OpenDocument]")

			End If

		Else

			'set locked

			'not locked so set to locked

			doc2.isLocked = "Locked"

			doc2.WhoLocked = username

			Call doc2.Save(True, False)

			Print("[" + db.filepath+"/0/"+doc2.UniversalID+"?EditDocument]")

		End If

	Else

		'set locked

		'not locked so set to locked

		doc2.isLocked = "Locked"

		doc2.WhoLocked = username

		Call doc2.Save(True, False)

		Print("[" + db.filepath+"/0/"+doc2.UniversalID+"?EditDocument]")

	End If

	

End If







Exit Sub

Whoops:

Dim strErrMsg

strErrMsg = "<HR>Error #" & Err & Chr$(10) & Error$ & Chr$(10) & "Line #" & Erl & | in sub/function: "| & Lsi_info(2) & |"|

strErrMsg = strErrMsg + "<br>Please report this to the IT staff<HR>"

Print strErrMsg



Exit Sub

End Sub

my email is idiots_united@hotmail.com

Subject: RE: Locking Document & Web - Agent Code

Thanks! Will try asap… been on the road. Uggghhh… thx for your email. See my donation to WSPA? …great org. Thx for the assistance.

Subject: RE: Locking Document & Web - Agent Code

Not a problem. I did see the donation, cheers for that, thought you were going to send 5 or 10 quid, but 25 is GREAT. I will keep checking this, so if you have any probs, leave a post.

Subject: RE: Locking Document & Web - Agent Code

Thanks… I really appreciate the assistance. Am getting tired of replication/save conflicts on the web! Will post update asap…

Subject: RE: Locking Document & Web - Agent Code

OK… I must be missing something simple. Here is each piece:

***it just opens the doc in edit mode and no lock. I access using another browser session and the edit button is still there.

  1. islocked view

view selection: SELECT islocked=“locked”

1st column formula: @Text(@DocumentUniqueID). The 1st column is sorted ascending.

  1. isLocked field

docid :=@DbLookup(“”;“”:“sample\sample.nsf”;“islocked”; @Text(@DocumentUniqueID); “”);

@If(@IsError(docid);“Unlocked”;“Locked”)

***i have the isLOcked field’s hide/when = isLocked=“Unlocked”

  1. Edit Button

@Command([RunAgent]; “(savelock)”)

***the edit button hide/when true = isLocked=“Locked”

  1. (savelock) agent

Sub Initialize

Dim session As New NotesSession

Dim db As NotesDatabase

Dim doc As NotesDocument

Dim doc2 As NotesDocument

Dim username As String

Dim curruser As Variant



On Error Goto whoops



Set db = session.CurrentDatabase

Set doc = session.DocumentContext

curruser = Evaluate({ @Name([CN];@UserName) }, doc)

username = curruser(0)

'following step is done because the user could have opened the doc and only hit the edit button a few minutes later

'by which time another user could have opened and edited/locked the same doc

Set doc2 = db.GetDocumentByUNID(doc.UniversalID)



If Not doc2 Is Nothing Then

	If doc2.HasItem( "isLocked" ) Then

		If doc2.isLocked(0) = "Locked" Then

			If doc2.HasItem( "WhoLocked") Then

				If doc2.WhoLocked(0) = curruser Then

'open in edit mode

'the person who locked it is trying to edit it, so allow this

					Print("[" + db.filepath+"/0/"+doc2.UniversalID+"?EditDocument]")

				Else

'open in read mode

'the person other than the person who locked it is trying to edit it, so do not allow this

					Print("[" + db.filepath+"/0/"+doc2.UniversalID+"?OpenDocument]")

				End If

			Else

'open in read mode

'system problem as there is no person assigned to the WhoLocked field, so do not allow this

				Print("[" + db.filepath+"/0/"+doc2.UniversalID+"?OpenDocument]")

			End If

		Else

'set locked

'not locked so set to locked

			doc2.isLocked = "Locked"

			doc2.WhoLocked = username

			Call doc2.Save(True, False)

			Print("[" + db.filepath+"/0/"+doc2.UniversalID+"?EditDocument]")

		End If

	Else

'set locked

'not locked so set to locked

		doc2.isLocked = "Locked"

		doc2.WhoLocked = username

		Call doc2.Save(True, False)

		Print("[" + db.filepath+"/0/"+doc2.UniversalID+"?EditDocument]")

	End If

	

End If



Exit Sub

Whoops:

Dim strErrMsg

strErrMsg = "<HR>Error #" & Err & Chr$(10) & Error$ & Chr$(10) & "Line #" & Erl & | in sub/function: "| & Lsi_info(2) & |"|

strErrMsg = strErrMsg + "<br>Please submit an APS Online support request.<HR>"

Print strErrMsg



Exit Sub

End Sub

  1. Guess I need to set the isLocked field back to “unLocked,” right? I was planning on doing this with the save/submit button.

Subject: RE: Locking Document & Web - Agent Code

2 things to try:1) Put a messagebox before each Print, so you can identify which print is being used ie

Messagebox(“Lock Agent Print 1”)

Print(“[” + db.filepath+“/0/”+doc2.UniversalID+“?EditDocument]”)

Then keep the server console open and watch for the messagebox.

Open the locked view in the client and open the doc on the browser. Refresh the view and make sure doc is not showing up. Then edit the doc and refresh the view to see if it is in there.

Subject: RE: Locking Document & Web (Need Help)

Thanks… will try before I respond! :slight_smile: Offer is still 100%… if this works, you just won a gift certificate. Will respond asap… send me an email to dominoadmin@hotmail.com. I’ll be able to send e-certificate via email… you an iTunes person? Let me try this… have wasted so much time on this. Am confident I was over-thinking this one…

Subject: RE: Locking Document & Web (Need Help)

IF you get this to work, instead of sending me a gift certificate, go along to www.wspadonations.org (World Society for the Protection of Animals) and make a donation. They need it more than I do.

Trust me, this is not a waste of time, because once you get this working, you can simply drop it into any database you work on from now on in. Not sure why everyone simply throws their hands in the air when you mention document locking via domino. Its viable, relatively simple (when compared with some of the other things we ask of Domino) and impresses the hell out of clients.

Subject: RE: Locking Document & Web (Need Help)

Almost forgot…

There are going to be instances where the user locks a doc and then closes the webpage with out saving or the server crashes before they save.

You will need to run an agent on all locked docs once a day, presumably at say 3am, that unlocks all locked docs.

Also, when you lock the doc, store the username of the person doing the locking. That way when they re-open the locked doc, or the administrator logs on and opens the locked docs, you can give them access to a button that will run that same unlocking agent on that locked document.

Subject: RE: Locking Document & Web (Need Help)

Wow… many thanks! That is admirable… as I am an adventurist, naturalist, etc. I’ll make donation and post link. A worthy cause…

***I have been on the road and am back at the office (ready to try!).

I agree -w- you 100%… it amazes me that there’s not more discussion around this subject. replication/save conflicts are a serious problem on the web.