示例:字段验证

此示例演示如何验证单个字段值。例如,以下代码段显示如何确保特定中的用户无法降低缺陷的优先级。

在此示例中,如果用户在 QATester 中,且正在修改 BG_PRIORITY 字段,BG_PRIORITY 字段的新值不能小于当前值。

此示例假定在项目的优先级字段列表中,以升序对值排序时,较低的优先级在前。例如,如果元素如下,则列表符合此需求:1 - 低,2 - 中,3 - 高

将代码添加到 Bug_FieldCanChange 事件过程,这样用户试图更改缺陷字段值时就会触发它。

Function Bug_FieldCanChange(FieldName, NewValue)
        ' Initialize the function's return value
	' to avoid unpredictable behavior.
        Bug_FieldCanChange = True 
        On Error Resume Next
        If User.IsInGroup("QATester") and FieldName ="BG_PRIORITY" _
	 Then
            If NewValue < Bug_Fields("BG_PRIORITY").Value then
                Bug_FieldCanChange = False
                msgbox "You do not have permission to lower " _
		 & "defect priority."
            Else
                Bug_FieldCanChange = True
            End If
        Else
            ' Enter your code here.
        End If
        PrintError "Bug_FieldCanChange"
        On Error GoTo 0
End Function