【原创】LS程序 - 判定文档在当前视图下是否唯一

作用
相信这种需求还是比较普遍的,根据文档中关键字段信息判断文档是否唯一,保证数据的准确性和不重复,这是大多数数据库所需要的。一下功能将程序编入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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值