LotusScript - 如何创建按钮来更改某些字段中的值并刷新表单?

LotusScript - How to create button to change values in certain fields and refresh form?

目前正在修改 LotusNotes 中的旧表单,如果用户编辑表单,某些字段将重置为空白。现在我需要将该功能放入一个按钮中,以便用户可以简单地进行编辑而无需重置这些字段,但仍允许他们在需要时使用重置功能。

我基本上所做的是复制启用此功能的表单部分中的 LotusScript 代码并将其粘贴到按钮操作中:

------------------------------------------------
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 错误并且表单没有改变。我错过了什么?

首先:永远不要在没有错误处理程序的情况下编写哪怕一行 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

并将 source1 的所有其他实例替换为 uidoc(您​​可以删除 Dim source1 as NotesUiDocument 行)然后它将起作用。