Solution: web unlocking

Form’s onUnload event calls the docOnUnLoad function. The agent gets a handle on the doc with the passed unid, compares who has it locked against who is closing the doc and if the names match, then the doc is unlocked, otherwise just exit. After that, the pausecomp function is called, which is the secret, it gives the agent time to run and unlock the doc. Without it, the onunload is not consistently called. Hope this helps, Kb

function docOnUnload() {

if ( document.forms[0].isNewDocTest.value == “no”) {

var pathname=(window.location.pathname); 

var noteid = document.forms[0].docUNID.value;

window.open(pathname.substring(0,(pathname.lastIndexOf('.nsf')+4))+"/webDocUnLock?OpenAgent&ID="+noteid,"_self");

pausecomp(1000)

}; 

}

function pausecomp(millis) {

var date = new Date();

var curDate = null;



do { curDate = new Date(); } 

while(curDate-date < millis);

}

********* code in agent everthing goes into the init sub portion of the agent.**********

Dim session As New NotesSession

Dim db As NotesDatabase

Dim tempDoc As NotesDocument

Dim lockedDoc As NotesDocument 

Dim charVariant As Variant

Dim currentholder As Variant

Dim testForDealer As Integer



Set db = session.CurrentDatabase

Set tempDoc = session.DocumentContext

queryString$ = tempDoc.QUERY_STRING(0)



'queryString$ = tempDoc.DocUNID(0)

'Messagebox ("queryString is " & queryString$)

docid$ = Mid$(queryString$, 14, Len(queryString$) )

Set lockedDoc = db.GetDocumentbyUNID(docid$)

If lockedDoc Is Nothing Then

	Messagebox("ERROR - could not find existing document " & Cstr(docid$) )

	Print "<SCRIPT LANGUAGE=JavaScript>"

	Print "window.close()"

	Print "</SCRIPT>"	

	Exit Sub

End If

'*********************** NOTE these following lines are necessary for us because we use common names everywhere, you may want to remove this translation if you want to compare heirarchical user names.

currentusername$ = session.EffectiveUserName

If Instr(currentusername$, "/O=") > 0 Then currentusername$ = Strleftback(currentusername$, "/O=")

If Instr(currentusername$, "/OU=") > 0 Then currentusername$ = Strleftback(currentusername$, "/OU=")

If Instr(currentusername$, "/OU=") > 0 Then currentusername$ = Strleftback(currentusername$, "/OU=")	

If Instr(currentusername$, "/OU=") > 0 Then currentusername$ = Strleftback(currentusername$, "/OU=")

If Instr(currentusername$, "/OU=") > 0 Then currentusername$ = Strleftback(currentusername$, "/OU=")

If Instr(currentusername$, "CN=") > 0 Then currentusername$ = Strright(currentusername$, "CN=")

Messagebox("currentusername is " & currentusername$)



currentholder = lockedDoc.LockHolders

lockedBy$ = Cstr(currentholder(0))



If Instr(lockedBy$, "/O=") > 0 Then lockedBy$ = Strleftback(lockedBy$, "/O=")

If Instr(lockedBy$, "/OU=") > 0 Then lockedBy$ = Strleftback(lockedBy$, "/OU=")

If Instr(lockedBy$, "/OU=") > 0 Then lockedBy$ = Strleftback(lockedBy$, "/OU=")	

If Instr(lockedBy$, "/OU=") > 0 Then lockedBy$ = Strleftback(lockedBy$, "/OU=")

If Instr(lockedBy$, "/OU=") > 0 Then lockedBy$ = Strleftback(lockedBy$, "/OU=")

If Instr(lockedBy$, "CN=") > 0 Then lockedBy$ = Strright(lockedBy$, "CN=")

Messagebox("lockedBy is " & lockedBy$)





'Messagebox ("current holder is" + currentholder(0) + " and the effective user name is " + currentusername$ )

If (lockedBy$ = currentusername$ ) Then	

	Call lockedDoc.UnLock

	'Messagebox ("UNLOCKING Document")

	Print "<SCRIPT LANGUAGE=JavaScript>"

	Print "window.close()"

	Print "</SCRIPT>"

Else

	Print "<SCRIPT LANGUAGE=JavaScript>"

	Print "window.close()"

	Print "</SCRIPT>"		

End If

********** end of agent data.

Hope this helps.