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.
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;
}