General Technical Discussions for Service

Get Involved. Join the Conversation.

Topic

    JN Hutchinson
    $answer->Products inside custom process failingAnswered
    Topic posted August 22, 2014 by JN HutchinsonGold Medal: 3,500+ Points 
    186 Views, 2 Comments
    Title:
    $answer->Products inside custom process failing
    Content:

    I'm using the following code to try to pull all the product IDs for a given answer.  If I run the code in a CP page, it works.  If I run it in a custom process, it returns null values.  (Similar behavior for Categories)

    In CP page, it pulls the answer via $answer = RNCPHP\Answer::fetch($aid,RNCPHP\RNObject::VALIDATE_KEYS_OFF);

    In Custom Process, it runs on the answer update event.

    NOTE: All other answer fields I try to access so far seem to work.  It is just the product and category fields that refuse to show up in a Custom Process.

    What am I missing?

     

     

    Version:
    May 2014
    Code Snippet:

    Best Comment

    Gurinderpal Singh

    Hi,

    Please fetch the product and category of answer with ROQL query().

    Replace your code with following code in CPM:

    $roql_result = RNCPHP\ROQL::query( "SELECT A.Products.ID,A.Products.LookupName from Answer A where A.ID=".$obj->ID )->next();
                    $i=0;
                    while($answer =  $roql_result->next())
                    {
                        $products[$i]['ID'] = $answer['ID'];
                        $products[$i]['LookupName'] = $answer['LookupName'];
                        $i++;
                    }

     

    NOTE:  In the CPM some fields are not Fetch directly by $obj.

    eg. Custom Fields of any object can't be fetch through $obj But with ROQL query() we can easily fetch custom field.

     

    Thanks,

    Gurinderpal

     

     

    Comment

     

    • Gurinderpal Singh

      Hi,

      Please fetch the product and category of answer with ROQL query().

      Replace your code with following code in CPM:

      $roql_result = RNCPHP\ROQL::query( "SELECT A.Products.ID,A.Products.LookupName from Answer A where A.ID=".$obj->ID )->next();
                      $i=0;
                      while($answer =  $roql_result->next())
                      {
                          $products[$i]['ID'] = $answer['ID'];
                          $products[$i]['LookupName'] = $answer['LookupName'];
                          $i++;
                      }

       

      NOTE:  In the CPM some fields are not Fetch directly by $obj.

      eg. Custom Fields of any object can't be fetch through $obj But with ROQL query() we can easily fetch custom field.

       

      Thanks,

      Gurinderpal

       

       

    • JN Hutchinson

      Thanks.  I'll try ROQL.

      The weird thing is there is no rhyme or reason to which will work and which will not.  For instance, some custom fields work just fine for me.  Even a custom object works fine.  But this standard field does not.  /shrug

      EDIT: Got this working last night.  The ROQL stuff is working like a charm.  Thanks!

      Josh