Link to home
Start Free TrialLog in
Avatar of mschwade
mschwade

asked on

Trying to get full first and last names of ClearQuest users from a certain group

So I have a dropdown field on a ClearQuest form that gets populated from a group that is created in the ClearQuest Users and Groups... My array below only brings back the usernames and I want it to bring back the first and last name for that particular username.  Anyone help with this?

Thanks!
MS

sub bus_sponsor_ChoiceList {
    my($fieldname) = @_;
    my @choices;
      my $group_BS = "Business";
      &UserChoiceLists($fieldname, $group_BS);
      @choices = sort @returnchoices;
    return @choices;
}
ASKER CERTIFIED SOLUTION
Avatar of mjcoyne
mjcoyne

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of mschwade
mschwade

ASKER

Nowhere in the script, I believe that's what this is doing:
     # tell it which group to pull from
      my $group_BS = "Business";
    # populate the choicelist from the above group
    &UserChoiceLists($fieldname, $group_BS);
   # sort the choicelist
      @choices = sort @returnchoices;
  # return the sorted choicelist from the group specified
    return @choices;
Here's what those lines are doing:

      my $group_BS = "Business";

Declares a variable $group_BS, scoped to the current sub function, and assigns it the value "Business"

    &UserChoiceLists($fieldname, $group_BS);

Calls the subfunction UserChoiceLists(), passing to it the scalar variables $fieldname and $group_BS.

      @choices = sort @returnchoices;

Populates a locally scoped empty array declared earlier in the sub function with the result of sorting a mystery and possibly empty array called @returnchoices.

    return @choices;

The subfunction ends, returning the possibly empty array @choices to whatever part of the script called the function to begin with.

You really need to track down the origin of @returnchoices.  Where is it declared (likely with the "my" keyword)?  Where else in the script does @returnchoices appear?
Maybe this will be easier to work off of, I get the same result... I thought the commented out parts would work, but I get an error.

sub bus_sponser_ChoiceList {
    my($fieldname) = @_;
    my @choices;
    my $group_BS = "Business";
    foreach $item (&UserChoiceLists($fieldname, $group_BS)) {
    # $userFullname = $item->GetFullName();
    if ($item ne "") {
     push(@choices, $item);
     # push(@choices, $userFullname)
    }
   }
    return @choices;
}
Does UserChoiceLists return an array?  If so, the first post from mjcoyne should work.  If not, then there is nothing to loop on.

Can you post the code for UserChoiceLists?
Here's my updated mess, I mean code:  Getting the following error message:

ERROR! Execution of a hook failed during the action Submit.  It was the FIELD_CHOICE_LIST hook of the field bus_sponsor, attached to the ChangeRequest "mydb00000083".  The reason for the failure was: ST(1) does not contaion a reference. at C:/Program Files/Rational/common/lib/perl4/site_perl/5.8.6/CQPerlExt.pm line 43.

sub bus_sponser_ChoiceList {
    my($fieldname) = @_;
    my @choices;
    $session = $entity->GetSession();
    my $group_BS = "Business";
    my $variable = "";
    foreach $item (&UserChoiceLists($fieldname, $group_BS)) {
    if (length($variable) > 0) {
      $variable = "$variable,$item";
      } else {
      $variable = "$item";
      }
     }
     my @users = split(/,/, $variable);
     $querydef = $session->BuildQuery("users");
     $querydef->BuildField("fullname");
     $querydef->BuildField("email");
     $operator = $querydef->BuildFilterOperator($CQPerlExt::CQ_BOOL_OP_OR);
     $operator->BuildFilter("fullname", $CQPerlExt::CQ_COMP_OP_EQ, \@users);
     $operator->BuildFilter("login_name", $CQPerlExt::CQ_COMP_OP_EQ, \@users );
     $resultset = $session->BuildResultSet(querydef);
     $resultSet->Execute;

     $status = $resultSet->MoveNext;
     my $fullnames = "";
     while ( $status == $CQPerlExt::CQ_SUCCESS ) {    
     $names = "";
     $names = $resultset->GetColumnValue(1);
     if (length($fullnames) > 0) {
      $fullnames = "$fullnames,$names";
      } else {
      $fullnames = "$names";
      }
      $status    = $resultset->MoveNext();
     }

     my @userfnames = split(/,/, $fullnames);
     @choices = sort @userfnames;
     return @choices;
}

SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Or try this:

use Data::Dumper;    #Put this at the top of the script

my @Returns=&UserChoiceLists($fieldname, $group_BS);
print Data::Dumper->Dump([\@Returns], ['UserChoiceLists return value']);
finally found it:

sub UserChoiceLists {      
      my($fieldname, $groups) = @_; #Strings from field script
      @group = split /,/,$groups;   #String to an array
      @returnchoices = ();               #Creating a blank array
      $session = $entity->GetSession();
    $session->OutputDebugString("ENTERING: GlobalScripts::AssignmentForm_fieldChanged\n");
    $cqquery = $session->BuildQuery("users");
      $cqquery->BuildField("login_name");
    $cqfilter = $cqquery->BuildFilterOperator($CQPerlExt::CQ_BOOL_OP_AND);
    $cqfilter->BuildFilter("groups.name", $CQPerlExt::CQ_COMP_OP_IN, \@group );
    $resultset = $session->BuildResultSet($cqquery);
    $resultset->Execute();

    $movenext = $resultset->MoveNext();
    while ($movenext == $CQPerlExt::CQ_SUCCESS) {
            my $loginname = $resultset->GetColumnValue(1);
            $session->OutputDebugString("loginname  = $loginname\n");
            push @returnchoices, $loginname;
            $movenext = $resultset->MoveNext();
      }
      return @returnchoices;
 }