Topic
  • 6 replies
  • Latest Post - ‏2012-11-22T08:16:58Z by SystemAdmin
SystemAdmin
SystemAdmin
24948 Posts

Pinned topic When call the method $entity->validate(),there will appear an error

‏2012-11-20T02:55:59Z |
When call the method $entity->validate(),there will appear an error:"No such file or directory".

I want to create a new record on ClearQuest,and the below is the method:
===========================================================================
To create a new record:

Determine what record types you can create by calling the GetSubmitEntityDefNames method of the Session object.
Call the BuildEntity method of the Session object.
Use methods of the Entity object to set values for fields in the record.
When you are done editing the record, validate it and commit your changes to the database by calling the Entity object's Validate and Commit methods, respectively.
===========================================================================

And the below is part of my code:
$arr=$session->GetSubmitEntityDefNames();
foreach(@$arr)
{
print "arr is:" ,$_,"\n";
}
$entity = $session->BuildEntity("Feture");
$entity->SetFieldValue("Name", "test001");
$entity->SetFieldValue("MDECUST", "test002");
$entity->SetFieldValue("Node", "MSC");
$entity->SetFieldValue("Office", "MSC");

$fieldNameList = $entity->GetFieldNames();
foreach $fieldname (@$fieldNameList)
{
print ">$fieldname\n";

$fieldinfoobj = $entity->GetFieldValue($fieldname),"\n";
print "filedvalue:",$fieldinfoobj->GetValue() , "\n\n";
}

$entity->SetFieldValue("Name", "aaa");

$fieldNameList = $entity->GetFieldNames();

foreach $fieldname (@$fieldNameList)
{
print ">$fieldname\n";

$fieldinfoobj = $entity->GetFieldValue($fieldname),"\n";
print "filedvalue:",$fieldinfoobj->GetValue() , "\n\n";
}
$entity->Validate() or die "can't Validate: $!\n";
$entity->Submit();
But when i run the code,an errow will appear:"No such file or directory"

So,What should i solve the problem???????
Thanks.
  • Lumart
    Lumart
    87 Posts

    Re: When call the method $entity->validate(),there will appear an error

    ‏2012-11-20T08:54:40Z  
    Dashuai,
    first: is this a hook or an external script?
    Second: you should insert some debugging inside it (use *$session->OutputDebugString(...)*).
    Anyway, I would not call the newly created record $entity, as $entity is a predefined variable in CQ, referring to the current record being edited.
    Call it, say, $MyEntity or something similar.
  • Lumart
    Lumart
    87 Posts

    Re: When call the method $entity->validate(),there will appear an error

    ‏2012-11-20T09:07:55Z  
    • Lumart
    • ‏2012-11-20T08:54:40Z
    Dashuai,
    first: is this a hook or an external script?
    Second: you should insert some debugging inside it (use *$session->OutputDebugString(...)*).
    Anyway, I would not call the newly created record $entity, as $entity is a predefined variable in CQ, referring to the current record being edited.
    Call it, say, $MyEntity or something similar.
    In addition: after a Validate, you should call a Commit (or a Revert if the Validate returned any error).
    Try the attached code to manage the Validation and Commit of a CQ record.
  • SystemAdmin
    SystemAdmin
    24948 Posts

    Re: When call the method $entity->validate(),there will appear an error

    ‏2012-11-20T09:45:16Z  
    I found why this error appears,but i still don't know how to solve it.

    #!/bin/perl

    use CQPerlExt;

    #--------------------------------------------------
    1. Create ClearQuest session object
    #--------------------------------------------------
    print "Creating ClearQuest Session\n" if $DEBUG;
    $session = CQSession::Build()
    or die "Can't create ClearQuest session object: $!";

    #--------------------------------------------------
    1. Session Logon
    #--------------------------------------------------
    my $master_db_name = "MASTR";
    my $user_login_name = "admin";
    my $database_set = "";

    my $databases = $session->GetAccessibleDatabases($master_db_name, $user_login_name, $database_set) or die "can't GetAccessibleDatabases:$!\n";
    my $count = $databases->Count() or die "can't count:$!\n";
    print "Database Count: " . $count . "\n";
    for($i=0; $i<$count; $i++){
    my $db_item = $databases->Item($i);
    my $db_name = $db_item->GetDatabaseName() or die "can't GetDatabaseName:$!\n";
    print "< "\n";
    }

    print "> ";
    my $db_name = <STDIN>; chomp $db_name;
    my $login_name = "admin";
    my $password = "";
    my $database_set = "";

    $session->UserLogon($login_name, $password, $db_name, $database_set) or die "can't logon because:$!\n";


    Then,the error will appear when the code run the last line:"can't logon because:No such file or directory"
  • Lumart
    Lumart
    87 Posts

    Re: When call the method $entity-&gt;validate(),there will appear an error

    ‏2012-11-20T11:16:29Z  
    I found why this error appears,but i still don't know how to solve it.

    #!/bin/perl

    use CQPerlExt;

    #--------------------------------------------------
    1. Create ClearQuest session object
    #--------------------------------------------------
    print "Creating ClearQuest Session\n" if $DEBUG;
    $session = CQSession::Build()
    or die "Can't create ClearQuest session object: $!";

    #--------------------------------------------------
    1. Session Logon
    #--------------------------------------------------
    my $master_db_name = "MASTR";
    my $user_login_name = "admin";
    my $database_set = "";

    my $databases = $session->GetAccessibleDatabases($master_db_name, $user_login_name, $database_set) or die "can't GetAccessibleDatabases:$!\n";
    my $count = $databases->Count() or die "can't count:$!\n";
    print "Database Count: " . $count . "\n";
    for($i=0; $i<$count; $i++){
    my $db_item = $databases->Item($i);
    my $db_name = $db_item->GetDatabaseName() or die "can't GetDatabaseName:$!\n";
    print "< "\n";
    }

    print "> ";
    my $db_name = <STDIN>; chomp $db_name;
    my $login_name = "admin";
    my $password = "";
    my $database_set = "";

    $session->UserLogon($login_name, $password, $db_name, $database_set) or die "can't logon because:$!\n";


    Then,the error will appear when the code run the last line:"can't logon because:No such file or directory"
    You'd better remove the "die" statement after the UserLogon method.
    I got a similar error, but after removing the "die" I was able to navigate in the CQ database.
    It looks like the UserLogon method returns false even if the logon was successful....
  • pdubovitsky
    pdubovitsky
    376 Posts

    Re: When call the method $entity-&gt;validate(),there will appear an error

    ‏2012-11-20T13:10:06Z  
    I found why this error appears,but i still don't know how to solve it.

    #!/bin/perl

    use CQPerlExt;

    #--------------------------------------------------
    1. Create ClearQuest session object
    #--------------------------------------------------
    print "Creating ClearQuest Session\n" if $DEBUG;
    $session = CQSession::Build()
    or die "Can't create ClearQuest session object: $!";

    #--------------------------------------------------
    1. Session Logon
    #--------------------------------------------------
    my $master_db_name = "MASTR";
    my $user_login_name = "admin";
    my $database_set = "";

    my $databases = $session->GetAccessibleDatabases($master_db_name, $user_login_name, $database_set) or die "can't GetAccessibleDatabases:$!\n";
    my $count = $databases->Count() or die "can't count:$!\n";
    print "Database Count: " . $count . "\n";
    for($i=0; $i<$count; $i++){
    my $db_item = $databases->Item($i);
    my $db_name = $db_item->GetDatabaseName() or die "can't GetDatabaseName:$!\n";
    print "< "\n";
    }

    print "> ";
    my $db_name = <STDIN>; chomp $db_name;
    my $login_name = "admin";
    my $password = "";
    my $database_set = "";

    $session->UserLogon($login_name, $password, $db_name, $database_set) or die "can't logon because:$!\n";


    Then,the error will appear when the code run the last line:"can't logon because:No such file or directory"
    // "can't logon because:No such file or directory"

    You are running it from UNIX box. Have you configured ClearQuest connection?

    Pavel
  • SystemAdmin
    SystemAdmin
    24948 Posts

    Re: When call the method $entity-&gt;validate(),there will appear an error

    ‏2012-11-22T08:16:58Z  
    Hi,Lumart.You are right!!

    I solve this problem according to your suggestion!

    Thanks very much!