2

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.

David W.
  • 105,218
  • 39
  • 216
  • 337

1 Answers1

4

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.

DVK
  • 126,886
  • 32
  • 213
  • 327
  • Yup. That was it. I had to put quotes around the value. In fact it worked if I just put quotes around the value of $buildsheetId in the call to my subroutine that contained the SetNameValue method. Very interesting. I would think that the API call would do the conversion, but I guess not. Interestingly, I have a third routine where I verify the buildsheet exists, but didn't have to quote "$buildsheetId". That routine builds a query, and I have to put the buildsheet ID in a list of one, and reference the list. Thanks! – David W. Dec 28 '10 at 20:42