当前在LotusNotes中重做旧表单,如果用户编辑表单,则某些字段将重置为空白。现在,我需要将该功能放入按钮中,以便用户可以简单地进行编辑而无需重置这些字段,但是仍然允许他们在需要时使用重置功能。</ p>
我基本上所做的是将LotusScript代码复制到启用该功能的Form部分中,并将其粘贴到按钮操作中:
------------------------------------------------
Reset Approval (Action) : (Declaration)
------------------------------------------------
Dim editflag as string
------------------------------------------------
Reset Approval (Action) : Click
------------------------------------------------
Sub Click(Source As button)
Dim w As New NotesUIWorkspace
Dim session As New NotesSession
Dim db As NotesDatabase
Dim doc As NotesDocument
Dim uidoc As NotesUIDocument
Set db = session.CurrentDatabase
Set uidoc = w.CurrentDocument
' Get value for Approver 1 and 2
Approver_1 = uidoc.FieldGetText( "Approver_1" )
Approver_2 = uidoc.FieldGetText( "Approver_2" )
status1 = uidoc.FieldGetText( "status1" )
status2 = uidoc.FieldGetText( "status2" )
author = uidoc.FieldGetText( "Author" )
submit = uidoc.FieldGetText( "submit" )
cname = session.CommonUserName & "/ASY/MAWA"
aname = session.UserName
'Msgbox submit
'Cannot edit if user is not the author or approver 1 and 2
If (aname <> author And cname <> Approver_1 And cname <> Approver_2) Then
Msgbox "You Dont Have The Authorization To Edit This Document", 16, "Access Restricted"
Continue = False
Exit Sub
End If
'''''''''''''If user is the author prompt warning if the form already approved
If (aname = author And (status1 = "Yes" Or status2 = "Yes")) Then
Message = "Editing This Document Will Reset The Approval Status" & Chr$(13) &_
"Do you wish to continue?"
YesNo = Messagebox(Message,36,"Continue?")
If YesNo = 7 Then
continue = False
Exit Sub
Else
editflag = "Y"
End If
End If
Dim doc1 As NotesDocument
Dim source1 As NotesUIDocument
'Use backend notes object to assign value to current document
Set doc1 = source1.Document
'Check if document in edit mode
If (source1.EditMode = True) Then
'If edit flag is "Y" then reset status1 and status2 value
If (editflag = "Y") Then
doc1.ReplaceItemValue "status1", ""
doc1.ReplaceItemValue "status2" ,""
doc1.ReplaceItemValue "submit" ,"progress"
End If
End If
'Refresh document to anable send button
Call source1.Refresh
End Sub
当我保存更改时,我没有收到任何错误消息,因此我认为没问题。但是,当我尝试对其进行测试时,出现了Object Variable is not set
错误,并且表单没有改变。我想念什么?
答案 0 :(得分:1)
首先:绝对不要在没有错误处理程序的情况下编写甚至一行LotusScript。将这些行放在代码周围:
On error goto ErrorHandler
...your code...
EndOfRoutine:
Exit Sub
ErrorHandler:
Msgbox err+"-"+error+" in line "+erl
Resume EndOfRoutine
然后您会发现该行中发生了错误
Set doc1 = source1.document
因为您从未设置uidoc1,而仅设置了uidoc。
将其更改为
Set doc1 = uidoc.Document
并使用uidoc替换source1的所有其他实例(您可以将Dim source1删除为NotesUiDocument行),然后它将起作用。