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

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
    ACCEPTED ANSWER

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

    ‏2012-12-14T14:15:47Z  in response to oxie21
    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
      ACCEPTED ANSWER

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

      ‏2012-12-14T14:16:37Z  in response to cglockner
      My previous post got messed up with the syntax.

      The correct line should be

      foreach $state (@$statelist) {

      -Christian
      • oxie21
        oxie21
        2 Posts
        ACCEPTED ANSWER

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

        ‏2012-12-14T15:25:48Z  in response to cglockner
        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
          ACCEPTED ANSWER

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

          ‏2012-12-19T09:20:30Z  in response to oxie21
          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.