Field choice list hook to display user information

This hook extracts user login names that are members of a group with access to this database and loads them into the choice list for this field.

VBScript


Sub AssignedTo_ChoiceList(fieldname, choices)

  ' fieldname As String

  ' choices As Object

  ' entityDef = Defect


   Dim sessionObj

   Dim queryObj

   Dim filterObj

   Dim resultSetObj


   Set sessionObj = GetSession()

   ' start building a query of the users 

   Set queryObj = sessionObj.BuildQuery("users")


   ' have the query return the desired field of the user object(s)

   queryObj.BuildField ("login_name") 


   ' filter for members of group "MyGroup" (whatever group you want)

   Set filterObj = queryObj.BuildFilterOperator(AD_BOOL_OP_AND)

   filterObj.BuildFilter "groups", AD_COMP_OP_EQ, "MyGroup"

   Set resultSetObj = sessionObj.BuildResultSet(queryObj)


   ' run it

   resultSetObj.Execute


   ' add each value in the returned column to the choicelist

   Do While resultSetObj.MoveNext = AD_SUCCESS

      choices.AddItem resultSetObj.GetColumnValue(1)

   Loop

End Sub 

Perl


sub AssignedTo_ChoiceList {

    my($fieldname) = @_;

    my @choices;

    # $fieldname as string scalar

    # @choices as string array

    # record type name is Defect

    # field name is myuser

    # use array operation to add items. For example:
    # push(@choices, "red", "green", "blue");


    my $session = $entity->GetSession();

    # start building a query of the users 

    my $queryDefObj = $session->BuildQuery("users");


    # have the query return the desired field of the user object(s)

    $queryDefObj->BuildField("login_name");


    # filter for members of group "MyGroup" (whatever group you want)

    my $filterOp = $queryDefObj->BuildFilterOperator( 

   $CQPerlExt::CQ_BOOL_OP_AND);

    my @array = ("MyGroup");

    $filterOp->BuildFilter("groups", $CQPerlExt::CQ_COMP_OP_EQ, \@array);

    my $resultSetObj = $session->BuildResultSet($queryDefObj);


    # run it

    $resultSetObj->Execute();


    # add each value in the returned column to the choicelist

    while ($resultSetObj->MoveNext() == $CQPerlExt::CQ_SUCCESS) {

         push(@choices,$resultSetObj->GetColumnValue(1));

    }

    return @choices;

}