• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1071
  • Last Modified:

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;
}
0
mschwade
Asked:
mschwade
  • 4
  • 3
  • 2
2 Solutions
 
mjcoyneCommented:
Where does @returnchoices get populated?  Is it returned by UserChoiceLists()?  If so, should it be:

my @returnchoices = &UserChoiceLists($fieldname, $group_BS);

What does UserChoiceLists() look like?
0
 
mschwadeAuthor Commented:
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;
0
 
mjcoyneCommented:
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?
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
mschwadeAuthor Commented:
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;
}
0
 
Adam314Commented:
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?
0
 
mschwadeAuthor Commented:
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;
}

0
 
mjcoyneCommented:
We really, really need to see UserChoiceLists() to be of any help...

As a debug measure, you might try:

foreach $item (&UserChoiceLists($fieldname, $group_BS)) {
     print "$item\n";
}

Some assumption you're making about the nature of the data returned is incorrect.
0
 
Adam314Commented:
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']);
0
 
mschwadeAuthor Commented:
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;
 }
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 4
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now