Topic
  • 4 replies
  • Latest Post - ‏2012-12-19T09:20:30Z by Lumart
oxie21
oxie21
2 Posts

Pinned topic Want to pull the States out of a Record Type

‏2012-12-14T13:53:45Z |
What is wrong with the following?

$CQSession->UserLogon("$user", "$pwd", "$database", "$schema");
print "\nSuccessfully logged on to the CQ User database...\n\n";

$queryDefObj = $CQSession->GetEntityDef("workorder");

#Get field list for State entity

my $state;
my (@statelist) = $queryDefObj->GetStateDefNames();
foreach $state (@statelist) {
print "State: $state\n";
}

I get:
Successfully logged o to the CQ User database...

State: ARRAY(0x1a9f180)
Updated on 2012-12-19T09:20:30Z at 2012-12-19T09:20:30Z by Lumart
  • cglockner
    cglockner
    345 Posts

    Re: Want to pull the States out of a Record Type

    ‏2012-12-14T14:15:47Z  
    Hello,

    GetStateDefNames returns a reference to an array and not an array. Therefore

    
    foreach $state (@statelist) 
    {
    {code
    }   should be
    
    foreach $state (@$statelist) {{code}

    -Christian
  • cglockner
    cglockner
    345 Posts

    Re: Want to pull the States out of a Record Type

    ‏2012-12-14T14:16:37Z  
    • cglockner
    • ‏2012-12-14T14:15:47Z
    Hello,

    GetStateDefNames returns a reference to an array and not an array. Therefore

    <pre class="jive-pre"> foreach $state (@statelist) { {code } should be </pre> foreach $state (@$statelist) {{code}

    -Christian
    My previous post got messed up with the syntax.

    The correct line should be

    foreach $state (@$statelist) {

    -Christian
  • oxie21
    oxie21
    2 Posts

    Re: Want to pull the States out of a Record Type

    ‏2012-12-14T15:25:48Z  
    • cglockner
    • ‏2012-12-14T14:16:37Z
    My previous post got messed up with the syntax.

    The correct line should be

    foreach $state (@$statelist) {

    -Christian
    Thank you Christian. I've added "$" between @ and statelist and the error goes away. (foreach $state (@$statelist) { )

    But, now I see that the list is actually empty, so the GetEntityDef (and/or GetStateDefNames), must be wrong.
  • Lumart
    Lumart
    87 Posts

    Re: Want to pull the States out of a Record Type

    ‏2012-12-19T09:20:30Z  
    • oxie21
    • ‏2012-12-14T15:25:48Z
    Thank you Christian. I've added "$" between @ and statelist and the error goes away. (foreach $state (@$statelist) { )

    But, now I see that the list is actually empty, so the GetEntityDef (and/or GetStateDefNames), must be wrong.
    Actually there is another error where you retrieve the list of states.
    As GetStateDefNames returns a reference to an array, the code should be:

    my ($statelist) = $queryDefObj->GetStateDefNames();

    The rest of code should now be ok.