作用
相信这种需求还是比较普遍的,根据文档中关键字段信息判断文档是否唯一,保证数据的准确性和不重复,这是大多数数据库所需要的。一下功能将程序编入function中,实际使用可以直接调用,配合参数应用
注: keyword2应该制定为UniqueID所对应的域或者直接用LS获取。
如下
Function unique_doc (viewname As String, keyword1 As String, keyword2 As String) As Variant
'================================================================================================
' This function is use to identify if the document is unique in the view and which activity you
' want to apply to the action
' viewname : keyword, the view you want to inquery
' keyword1 : the fieldname you want to match to make sure if the document is unique
' keyword2 : the value you input which you want to check if it's a dupliate one in the current DB
'================================================================================================
On Error Goto sl
Dim ss As New NotesSession
Dim ws As New NotesUIWorkspace
Dim uidoc As NotesUIDocument
Dim doc As NotesDocument
Dim uninfo As Variant
Dim existinfo As Variant
Set uidoc = ws.CurrentDocument
Set doc = uidoc.Document
Dim tempAsso As Variant
Dim temval As Variant
' identify if the record is a replicate one when user create new doc.
If uidoc.IsNewDoc Then
existinfo = Evaluate(|@Dbcolumn("":"NoCache";"";"|+viewname+|";1)|)
Forall r In existinfo
If r = keyword1 Then
temval = "False"
End If
If temval = "False" Then
unique_doc = False
Exit Function
End If
End Forall
unique_doc = True
Exit Function
Else
' Identify the existed document when user edit it, make sure the document is unique.
tempAsso = doc.UniversalID
existinfo = Evaluate(|@Dblookup("":"NoCache";"";"|+viewname+|";"|+keyword1+|";"|+keyword2+|")|)
unique_doc = True
If Not Isempty(existinfo) Then
Forall r In existinfo
If r <> tempAsso Then
temval = "False"
End If
End Forall
If temval = "False" Then
unique_doc = False
Exit Function
End If
End If
End If
Exit Function
sl:
Msgbox Error & " " & Erl
End Function
相信这种需求还是比较普遍的,根据文档中关键字段信息判断文档是否唯一,保证数据的准确性和不重复,这是大多数数据库所需要的。一下功能将程序编入function中,实际使用可以直接调用,配合参数应用
注: keyword2应该制定为UniqueID所对应的域或者直接用LS获取。
如下
Function unique_doc (viewname As String, keyword1 As String, keyword2 As String) As Variant
'================================================================================================
' This function is use to identify if the document is unique in the view and which activity you
' want to apply to the action
' viewname : keyword, the view you want to inquery
' keyword1 : the fieldname you want to match to make sure if the document is unique
' keyword2 : the value you input which you want to check if it's a dupliate one in the current DB
'================================================================================================
On Error Goto sl
Dim ss As New NotesSession
Dim ws As New NotesUIWorkspace
Dim uidoc As NotesUIDocument
Dim doc As NotesDocument
Dim uninfo As Variant
Dim existinfo As Variant
Set uidoc = ws.CurrentDocument
Set doc = uidoc.Document
Dim tempAsso As Variant
Dim temval As Variant
' identify if the record is a replicate one when user create new doc.
If uidoc.IsNewDoc Then
existinfo = Evaluate(|@Dbcolumn("":"NoCache";"";"|+viewname+|";1)|)
Forall r In existinfo
If r = keyword1 Then
temval = "False"
End If
If temval = "False" Then
unique_doc = False
Exit Function
End If
End Forall
unique_doc = True
Exit Function
Else
' Identify the existed document when user edit it, make sure the document is unique.
tempAsso = doc.UniversalID
existinfo = Evaluate(|@Dblookup("":"NoCache";"";"|+viewname+|";"|+keyword1+|";"|+keyword2+|")|)
unique_doc = True
If Not Isempty(existinfo) Then
Forall r In existinfo
If r <> tempAsso Then
temval = "False"
End If
End Forall
If temval = "False" Then
unique_doc = False
Exit Function
End If
End If
End If
Exit Function
sl:
Msgbox Error & " " & Erl
End Function