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($fieldnam e, $group_BS);
@choices = sort @returnchoices;
return @choices;
}
Thanks!
MS
sub bus_sponsor_ChoiceList {
my($fieldname) = @_;
my @choices;
my $group_BS = "Business";
&UserChoiceLists($fieldnam
@choices = sort @returnchoices;
return @choices;
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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($fieldnam e, $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?
my $group_BS = "Business";
Declares a variable $group_BS, scoped to the current sub function, and assigns it the value "Business"
&UserChoiceLists($fieldnam
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?
ASKER
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($fieldna me, $group_BS)) {
# $userFullname = $item->GetFullName();
if ($item ne "") {
push(@choices, $item);
# push(@choices, $userFullname)
}
}
return @choices;
}
sub bus_sponser_ChoiceList {
my($fieldname) = @_;
my @choices;
my $group_BS = "Business";
foreach $item (&UserChoiceLists($fieldna
# $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?
Can you post the code for UserChoiceLists?
ASKER
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/CQPerlEx t.pm line 43.
sub bus_sponser_ChoiceList {
my($fieldname) = @_;
my @choices;
$session = $entity->GetSession();
my $group_BS = "Business";
my $variable = "";
foreach $item (&UserChoiceLists($fieldna me, $group_BS)) {
if (length($variable) > 0) {
$variable = "$variable,$item";
} else {
$variable = "$item";
}
}
my @users = split(/,/, $variable);
$querydef = $session->BuildQuery("user s");
$querydef->BuildField("ful lname");
$querydef->BuildField("ema il");
$operator = $querydef->BuildFilterOper ator($CQPe rlExt::CQ_ BOOL_OP_OR );
$operator->BuildFilter("fu llname", $CQPerlExt::CQ_COMP_OP_EQ, \@users);
$operator->BuildFilter("lo gin_name", $CQPerlExt::CQ_COMP_OP_EQ, \@users );
$resultset = $session->BuildResultSet(q uerydef);
$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;
}
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/
sub bus_sponser_ChoiceList {
my($fieldname) = @_;
my @choices;
$session = $entity->GetSession();
my $group_BS = "Business";
my $variable = "";
foreach $item (&UserChoiceLists($fieldna
if (length($variable) > 0) {
$variable = "$variable,$item";
} else {
$variable = "$item";
}
}
my @users = split(/,/, $variable);
$querydef = $session->BuildQuery("user
$querydef->BuildField("ful
$querydef->BuildField("ema
$operator = $querydef->BuildFilterOper
$operator->BuildFilter("fu
$operator->BuildFilter("lo
$resultset = $session->BuildResultSet(q
$resultSet->Execute;
$status = $resultSet->MoveNext;
my $fullnames = "";
while ( $status == $CQPerlExt::CQ_SUCCESS ) {
$names = "";
$names = $resultset->GetColumnValue
if (length($fullnames) > 0) {
$fullnames = "$fullnames,$names";
} else {
$fullnames = "$names";
}
$status = $resultset->MoveNext();
}
my @userfnames = split(/,/, $fullnames);
@choices = sort @userfnames;
return @choices;
}
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Or try this:
use Data::Dumper; #Put this at the top of the script
my @Returns=&UserChoiceLists( $fieldname , $group_BS);
print Data::Dumper->Dump([\@Retu rns], ['UserChoiceLists return value']);
use Data::Dumper; #Put this at the top of the script
my @Returns=&UserChoiceLists(
print Data::Dumper->Dump([\@Retu
ASKER
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->OutputDebugStrin g("ENTERIN G: GlobalScripts::AssignmentF orm_fieldC hanged\n") ;
$cqquery = $session->BuildQuery("user s");
$cqquery->BuildField("logi n_name");
$cqfilter = $cqquery->BuildFilterOpera tor($CQPer lExt::CQ_B OOL_OP_AND );
$cqfilter->BuildFilter("gr oups.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->OutputDebugStrin g("loginna me = $loginname\n");
push @returnchoices, $loginname;
$movenext = $resultset->MoveNext();
}
return @returnchoices;
}
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->OutputDebugStrin
$cqquery = $session->BuildQuery("user
$cqquery->BuildField("logi
$cqfilter = $cqquery->BuildFilterOpera
$cqfilter->BuildFilter("gr
$resultset = $session->BuildResultSet($
$resultset->Execute();
$movenext = $resultset->MoveNext();
while ($movenext == $CQPerlExt::CQ_SUCCESS) {
my $loginname = $resultset->GetColumnValue
$session->OutputDebugStrin
push @returnchoices, $loginname;
$movenext = $resultset->MoveNext();
}
return @returnchoices;
}
ASKER
# tell it which group to pull from
my $group_BS = "Business";
# populate the choicelist from the above group
&UserChoiceLists($fieldnam
# sort the choicelist
@choices = sort @returnchoices;
# return the sorted choicelist from the group specified
return @choices;