Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Lotus notes 在querysave中通过自定义类将值保存到文档时出现问题_Lotus Notes_Lotus_Lotus Domino_Lotusscript - Fatal编程技术网

Lotus notes 在querysave中通过自定义类将值保存到文档时出现问题

Lotus notes 在querysave中通过自定义类将值保存到文档时出现问题,lotus-notes,lotus,lotus-domino,lotusscript,Lotus Notes,Lotus,Lotus Domino,Lotusscript,我已经编写了一个小的定制类来运行LotusNotes8.5.2中的审计跟踪。我在自定义类中设置了NotesRichTextItem的值,一切看起来都很好。当我退出自定义类时,返回Querysave并检查Source.Document,我可以很好地看到值。查询保存完成后(自定义类调用后的行是End Sub),我检查文档属性,字段为空。我将包括下面的所有代码,尽管从querysave调用的函数是querySaveCheckValues(我传入源代码) 自定义类 Option Public Optio

我已经编写了一个小的定制类来运行LotusNotes8.5.2中的审计跟踪。我在自定义类中设置了NotesRichTextItem的值,一切看起来都很好。当我退出自定义类时,返回Querysave并检查Source.Document,我可以很好地看到值。查询保存完成后(自定义类调用后的行是End Sub),我检查文档属性,字段为空。我将包括下面的所有代码,尽管从querysave调用的函数是querySaveCheckValues(我传入源代码)

自定义类

Option Public
Option Declare

Public Class AuditTrail
REM boolean to audit all document items or use item list
Private includeAllItems As Boolean

Private currentDoc As NotesDocument
Private session As NotesSession
Private AUDIT_FIELD_LIST As String
Private AUDIT_FIELD As string
Private auditFieldList As NotesItem
Private postOpenValues List As String
Private auditField As NotesRichTextItem
Private MULTI_VALUE_SEPARATOR As String

'default message value insert strings
Private INSERT_FIELD_NAME As String
Private INSERT_OLD_VALUE As String
Private INSERT_NEW_VALUE As string

'message string defaults
Private DEFAULT_MESSAGE_CHANGE As String

'********** Sub new **********
Sub New(Source As NotesUIDocument)
    dim currentDoc As NotesDocument

    'put received uiDoc into NotesDocument
    Set currentDoc = source.Document


    REM set some class variables
    setDefaultStrings

    includeAllItems = True              'Details to all items on      document
    Set session = New NotesSession()

    REM Check if the pre-defined audit field exists. If it doesn't we will audit all fields
    If currentDoc.hasItem(AUDIT_FIELD_LIST) Then
        'check if audit field list has at least one value
        If UBound(currentDoc.GetItemValue(AUDIT_FIELD_LIST)) > 0 Then
            includeAllItems = False

            'assign field to NotesItem
            Set auditFieldList = currentDoc.GetFirstItem(AUDIT_FIELD_LIST)

        End If
    End If

    'get handle to audit field
    If Source.Isnewdoc Then
        Set auditField = New NotesRichTextItem(currentDoc, AUDIT_FIELD)
    End If
    Set auditField = currentDoc.GetFirstItem(AUDIT_FIELD)
End Sub





'********** collect values from current document **********
Function postOpenCollectValues(Source As NotesUIDocument)
    Dim currentDoc As NotesDocument
    Dim docItem As NotesItem
    Dim fieldName As String
    Dim fieldValue As String

    Set currentDoc = Source.Document

    If includeAllItems = False then
    If Not auditFieldList Is Nothing Then
        'list through values, find field and add to list
        Dim i%
        For i = 0 To UBound(auditFieldList.Values)
            fieldName = auditFieldList.Values(i)

            'look for item on document
            If currentDoc.Hasitem(fieldName) Then
                Set docItem  = currentDoc.GetFirstItem(fieldName)

                'check if item is multivalue
                If UBound(docItem.Values) > 0 Then
                    fieldValue = Join(docItem.Values,MULTI_VALUE_SEPARATOR)
                Else
                    fieldValue = docItem.Values(0)
                End If

                'convert value to string and put into list
                postOpenValues(fieldName) = fieldValue
            End If
        Next
    End If
    End if
End Function


'********** Query save check to see if any values have changed **********
Function querySaveCheckValues(Source As NotesUIDocument)
    Dim docItem As NotesItem
    Dim fieldName As String
    Dim oldValue, newValue As String

    Set currentDoc = Source.Document
    'Use list of fields generated during post open to save from etting errors when new fields
    'are added to forms
    ForAll x In postOpenValues
        'eliminate mess if field has been removed from form
        If currentDoc.hasItem(ListTag(x)) Then
            Set docItem = currentDoc.GetFirstItem(ListTag(x))
            fieldName = ListTag(x)

            'compare old and new value
            oldValue = x

            If UBound(docItem.Values) > 0 Then
                newValue = Join(docItem.Values,MULTI_VALUE_SEPARATOR)
            Else
                newValue = docItem.Values(0)
            End If

            Call me.compareValues(fieldName, CStr(oldValue), Newvalue)
        End If

    End ForAll

    'make sure any changes added to audit field in backend and not overwriten
'   Call Source.Refresh(true)
End Function


'********** Simple function to write lines to audit **********
Private Function writeAudit(message As String)
    Dim tmpItem As NotesRichTextItem
    Dim dateTime As New NotesDateTime(Now)
    Dim nameItem As New NotesName(session.Username)

    'take a copy of the current audit field content and blank audit
    Set tmpItem = New NotesRichTextItem(currentDoc, "tmpAudit")
    Call tmpItem.AppendRTItem(AuditField)
    Call auditField.Remove()

    'create a new audit field item and add new message
    Set AuditField = New NotesRichTextItem(currentDoc, AUDIT_FIELD)

    Call AuditField.AppendText(CStr(dateTime.LSLocalTime))
    Call AuditField.AddTab(1)
    Call AuditField.AppendText(nameItem.Abbreviated)
    Call AuditField.AddTab(1)
    Call AuditField.AppendText(message)

    'append previous audit field content
    Call AuditField.AppendRtItem(tmpItem)
    Call tmpItem.remove()
End Function



'********** Function to compare single and multi values **********
Private Function compareValues(fieldName As String, oldValue As String, newValue As String)
    Dim Message As String

    'check for multi value
    If InStr(oldValue,MULTI_VALUE_SEPARATOR) = 0 Then
        'single value
        If newValue <> oldValue Then
            'prepare message
            Message = prepareMessage(fieldName, oldValue, newValue, "CHANGE")
            Call writeAudit(Message)
        End If

    End If


End Function



'********** Replace values in default message with old and new values **********
Private Function prepareMessage(fieldName As String, oldValue As String, newValue As String, messageType As String) As string
    Dim tmpMessage As String

    'case statement for type
    Select Case messageType
        Case "CHANGE"
            tmpMessage = DEFAULT_MESSAGE_CHANGE

            'replace default insert text with real field name   
            tmpMessage = Replace(tmpMessage,INSERT_FIELD_NAME,fieldName)

            'old value
            tmpMessage = Replace(tmpMessage,INSERT_OLD_VALUE,oldValue)

            'new value
            tmpMessage = Replace(tmpMessage,INSERT_NEW_VALUE,newValue)
    End Select

    prepareMessage = tmpMessage
    Exit function
End Function



'********** Little function to setup our equivelant of constants **********
Private Function setDefaultStrings
    AUDIT_FIELD_LIST = "auditFieldList" 'default audit field list name
    AUDIT_FIELD = "AuditField"          'field used to store audit
    MULTI_VALUE_SEPARATOR = "~"         'Used to combine and split values in a multi value item

    'Default message insert strings
    INSERT_FIELD_NAME = "%FIELDNAME%"
    INSERT_OLD_VALUE = "%OLDVALUE%"
    INSERT_NEW_VALUE = "%NEWVALUE%"


    'Messages Strings
    DEFAULT_MESSAGE_CHANGE = "Value of field '" & INSERT_FIELD_NAME & _
    "' amended from '" & INSERT_OLD_VALUE & "' to '" & INSERT_NEW_VALUE & "'"
End Function



'********** handle error messages generated by this code **********
Private Function handleErrors
    const DEFAULT_ERROR_MESSAGE = "Unable to write audit information - an error occured"
    'if we have a handle on the audit field write an entry
    If Not auditField Is Nothing Then
        writeAudit(DEFAULT_ERROR_MESSAGE)
    End If
End Function

 End Class 
选项公共
选项声明
公共类审计线索
REM布尔值,用于审核所有文档项目或使用项目列表
私有includealitems作为布尔值
Private currentDoc As notes文档
作为noteSession的私有会话
私有审核\字段\列表为字符串
私有审核_字段作为字符串
私有auditFieldList作为NotesItem
私有postOpenValues列表为字符串
私有审核字段作为NotesRichTextItem
专用多值分隔符作为字符串
'默认消息值插入字符串
专用插入\字段\名称作为字符串
私有插入\u旧值作为字符串
私有插入\新\值作为字符串
'消息字符串默认值
私有默认消息更改为字符串
'**********次新**********
子新文件(源文件为NOTESUI文件)
dim currentDoc As NOTES文档
'将收到的uiDoc放入NotesDocument
设置currentDoc=source.Document
REM设置一些类变量
SetDefaultString
includealitems=True“文档上所有项目的详细信息”
设置会话=新的NotesSession()
REM检查预定义的审核字段是否存在。如果没有,我们将审核所有字段
如果currentDoc.hasItem(审核字段列表),则
'检查审核字段列表是否至少有一个值
如果UBound(currentDoc.GetItemValue(审核字段列表))大于0,则
includealitems=False
'将字段分配给NotesItem
设置auditFieldList=currentDoc.GetFirstItem(审核字段列表)
如果结束
如果结束
'获取审核字段的句柄
如果Source.Isnewdoc那么
Set auditField=New NotesRichTextItem(currentDoc,AUDIT_字段)
如果结束
Set auditField=currentDoc.GetFirstItem(审核字段)
端接头
'*******从当前文档收集值**********
函数postOpenCollectValues(源代码为NotesUIDocument)
Dim currentDoc As NOTES文档
将docItem设置为NotesItem
将字段名设置为字符串
将字段值设置为字符串
设置currentDoc=Source.Document
如果includealitems=False,则
如果没有,那么auditFieldList什么都不是
'通过值列出,查找字段并添加到列表中
Dim i%
对于i=0到UBound(auditFieldList.Values)
fieldName=auditFieldList.Values(i)
'查找文档上的项目
如果currentDoc.Hasitem(字段名),则
Set-docItem=currentDoc.GetFirstItem(字段名)
'检查项目是否为多值
如果UBound(docItem.Values)>0,则
fieldValue=Join(docItem.Values,多值分隔符)
其他的
fieldValue=docItem.Value(0)
如果结束
'将值转换为字符串并放入列表
postOpenValues(fieldName)=fieldValue
如果结束
下一个
如果结束
如果结束
端函数
'**********查询保存检查以查看是否有任何值已更改**********
函数QuerySaveCheckValue(源代码为NotesUIDocument)
将docItem设置为NotesItem
将字段名设置为字符串
Dim oldValue,newValue作为字符串
设置currentDoc=Source.Document
'使用post open期间生成的字段列表保存新字段时的错误
'添加到表单中
在后OpenValue中的所有x
'如果字段已从表单中删除,则消除混乱
如果currentDoc.hasItem(ListTag(x))那么
Set docItem=currentDoc.GetFirstItem(列表标签(x))
fieldName=ListTag(x)
“比较新旧价值
oldValue=x
如果UBound(docItem.Values)>0,则
newValue=Join(docItem.Values,多值分隔符)
其他的
newValue=docItem.Value(0)
如果结束
调用我。比较值(字段名、CStr(旧值)、新值)
如果结束
端孔
'确保添加到后端审核字段的任何更改都不会被覆盖
'调用源。刷新(true)
端函数
'**********编写要审核的行的简单函数**********
专用函数writeAudit(消息为字符串)
Dim tmpItem As NOTES RICHTEXT项目
Dim dateTime作为新NotesDateTime(现在)
Dim nameItem作为新的NotesName(session.Username)
'复制当前审核字段内容和空白审核
设置tmpItem=newnotesrichtextItem(当前文档,“tmpAudit”)
调用tmpItem.appendrItem(AuditField)
调用auditField.Remove()
'创建新审核字段项并添加新消息
Set AuditField=New NotesRichTextItem(currentDoc,AUDIT_字段)
调用AuditField.AppendText(CStr(dateTime.LSLocalTime))
调用AuditField.AddTab(1)
调用AuditField.AppendText(nameItem.缩写)
调用AuditField.AddTab(1)
调用AuditField.AppendText(消息)
'附加上一个审核字段内容
调用AuditField.appendrItem(tmpItem)
调用tmpItem.remove()
端函数
'*******函数用于比较单个值和多个值**********
私有函数compareValues(字段名为字符串,oldValue为字符串,newValue为字符串)
将消息设置为字符串
'检查多值
如果InStr(oldValue,多值分隔符)=0,则
“单一价值
如果newValue oldValue那么
“准备消息
消息=准备消息(字段名、旧值、新值、“更改”)
调用writeAudit(消息)
如果结束
如果结束
端函数
'**********用新旧值替换默认消息中的值*********