Example: Changing a Field Based on the User Group

This example demonstrates how you can change a field value according to the user group of the user entering the defect.

In this example, the user-defined field BG_USER_01 is a detection mode field in which the user who detected the defect can enter the way in which it was discovered. Possible values are Formal testing, Informal testing, and BTW.

The example sets the value of the detection mode field to BTW when a defect is opened by a user who is not in the QA Tester group. If the defect is opened by a user who is in the QA Tester group, the default value Formal testing is set.

Add the code to event procedure Bug_New, so that it is triggered when a defect is added.

Sub Bug_New
        On Error Resume Next
        If not User.IsInGroup("QATester") then
            Bug_Fields("BG_USER_01").Value = "BTW"
            Bug_Fields("BG_USER_01").Value = "Formal testing"
        End If
        PrintError "Bug_New"
        On Error GoTo 0
End Sub