Integrations and APIs for Service

Get Involved. Join the Conversation.

Topic

    Kurt Helfrich
    Connect for PHP - Can't see elements of an answer's...Answered
    Topic posted May 22, 2013 by Kurt HelfrichGold Trophy: 10,000+ Points, tagged Connect PHP 
    292 Views, 3 Comments
    Title:
    Connect for PHP - Can't see elements of an answer's Products array
    Content:

    I'm stumped.  I am trying to do some work with access control based on the products associated to an answer.

    I'm on a clone of the answers/detail page, and I added some code to start figuring out the syntax.

    The fetch of the answer is working OK, and when I print the answer ID or count($ans->Products), I get the right value.

    As my first test, I wanted to print the Name of each ServiceProduct in the array, but I can't.

    This seems to be working OK - not throwing an exception: $p = $ans->Products->fetch($i);

    How would I access the Name of $p, if not $p->Name?  I tried $p->Name->value, too.  No dice.

    Ultimately, I need to look at the root of the products and make some decisions based on that.

    Does anyone have any ideas?

    Version:
    August 2012
    Code Snippet:

    Best Comment

    Anuj Behl

    Hi,

    There's no need to fetch the Products again after you have the parent object Answer fetched already. Since, $ans->Products is an array of ServiceProducts object, we can access the individual products using the index. So, to get the Products name, the correct syntax would be

    for ($i = 0; $i < $lim; $i++)
    {
        $ans->Products[$i]->LookupName;
        // or (both will return product name)
        $ans->Products[$i]->Name;
    }

    To get the complete idea of object model, you can refer Connect PHP API documentation

    Regards,

    Anuj

    Comment

     

    • Kurt Helfrich

      Oh, and I tried using RightNow\Connect\v1_1 instead of v1_2.  No joy with that, either.

    • Anuj Behl

      Hi,

      There's no need to fetch the Products again after you have the parent object Answer fetched already. Since, $ans->Products is an array of ServiceProducts object, we can access the individual products using the index. So, to get the Products name, the correct syntax would be

      for ($i = 0; $i < $lim; $i++)
      {
          $ans->Products[$i]->LookupName;
          // or (both will return product name)
          $ans->Products[$i]->Name;
      }

      To get the complete idea of object model, you can refer Connect PHP API documentation

      Regards,

      Anuj

    • Kurt Helfrich

      That worked!  Thanks very much, Anuj.  I used the same syntax successfully for the Phones array on the Contact object, so I think I put on some syntax blinders with respect to this situation.  I'll have to look at the object model and see what the difference is, so I understand.

      I looked through the documentation, and I have noticed that they have a lot of examples that show how to do C-UD operations, but not a lot on how to just Read the data, and at least for me, that's what I do the most at present, and for me, Reading seems to be a problem.  Maybe I need new Reading glasses that can illuminate the correct syntax as well as magnify the font so I can see it.  But I haven't used Connect for PHP that much, yet, so I see I have a lot to learn.

      Thanks again.