Question

I have a ClearQuest API script written in Perl. If I do this:

#print qq(DEBUG: Buildsheet ID is "$buildsheetId"\n);
$cq->SetNameValue("ParentBuildSheetID", $buildsheetId);

#
# Now Create the Record Type and Fill in the Fields
#
my $record;
eval { $record = $cq->BuildEntity(TASK_RECORD_TYPE); };
if ($@) {
    croak qq(Error when attempting to create record type ")
    . TASK_RECORD_TYPE . qq("\n$@\n);
}
if (not $record) {
    die qq(Cannot create entity ") . TASK_RECORD_TYPE . qq("\n);
}

I get the following error:

ST(2) does not contain a string. at D:/Program Files/Rational/Common/lib/perl5/site_perl/5.8.6/CQPerlExt.pm line 43.

I traced this error message (THX CQ for not mentioning where in MY script where the error occurred) to this line:

$cq->SetNameValue("ParentBuildSheetID", $buildsheetId);

Hmmm... Maybe I didn't set $buildsheetId. Let me check by printing out the DEBUG statement preceding where I set it:

print qq(DEBUG: Buildsheet ID is "$buildsheetId"\n);
$cq->SetNameValue("ParentBuildSheetID", $buildsheetId);

#
# Now Create the Record Type and Fill in the Fields
#
my $record;
eval { $record = $cq->BuildEntity(TASK_RECORD_TYPE); };
if ($@) {
    croak qq(Error when attempting to create record type ")
    . TASK_RECORD_TYPE . qq("\n$@\n);
}
if (not $record) {
    die qq(Cannot create entity ") . TASK_RECORD_TYPE . qq("\n);
}

(NOTE: Same code as above, but with previous print debugging statement enabled.)

Now it works!

Why does it work by merely printing out the value? This isn't the only place where I have this issue:

print qq(DEBUG: \$buildsheetId = "$buildsheetId"\n);
my $record = $cq->GetEntity(BSHEET_RECORD_TYPE, $buildsheetId);

Again, GetEntity fails unless I print out the variable $buildsheetId.

Why does it matter if I print out the Perl value of a variable before I do a ClearQuest API call?


UPDATE

Here's the entire output of my script:

H:\>addTask.cqpl -user WeintraubH -pass Cape01may -buildsheet 5618 -task cm  
DEBUG: Buildsheet ID is "5618"
Subroutine NoteEntryInit redefined at (eval 1) line 850.
Subroutine SetLog redefined at (eval 1) line 1084.
DEBUG: $buildsheetId = "5618"

Note that my script is only 559 lines long, so the Subroutine errors aren't from my program. However, the two DEBUG: lines are. One is before creating the BuildEntity method and another before a GetEntity method. I'll have to trace down where those Subroutine redefined lines are coming from. I take it they're some sort of VB CQ hook running.

Was it helpful?

Solution

See if doing this helps (remove the debug print):

$cq->SetNameValue("ParentBuildSheetID", $buildsheetId . "");

or

$cq->SetNameValue("ParentBuildSheetID", "$buildsheetId");

If it works, your problem was that somehow, your API checks if a value is an int or a string (I'm assuming that ClearQuest innards are in C, not pure Perl, so there's a difference in terms of how your value was created - see http://www.sdsc.edu/~moreland/courses/IntroPerl/docs/manual/pod/perlguts.html#Working_with_SVs ).

By either quoting the variable or appending an empty string, you convert it into an expected string.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top