Integrations and APIs for Service

Get Involved. Join the Conversation.

Topic

    Nigel Oliver
    Returning the Category Parents ID's in PHP API
    Topic posted May 9, 2019 by Nigel OliverBronze Medal: 1,250+ Points, tagged Connect PHP, Custom Process Models - CPMs 
    62 Views, 2 Comments
    Title:
    Returning the Category Parents ID's in PHP API
    Summary:
    How to return the Parents ID of Category in PHP API
    Content:

    Hi All

    Ok so we are returning the Category ID's in PHP API By using the following:

    $catID = $incident->Category->ID;

    We are now trying to return the Category Parents ID as well but cant seem to figure it out, we have tried the following but get "cant return property of an object".

    $parCatID = £incident->Category->Parents->ID;

    Does anyone know the correct syntax ?

    Thanks!

    Nigel

    Version:
    18C

    Comment

     

    • Sebastiaan Draaisma

      Hi Nigel.

      I noticed a typo in

      $parCatID = £incident->Category->Parents->ID; // should probably be $

      In ROQL this is:

      • Incident.Product.Parent.ID
      • Incident.Category.Parent.ID

      The PHP Connect documentation states

      Named ID that holds a hierarchical value (e.g., ServiceProduct). It is similar to a NamedID, but the parent hierarchy is provided as a convenience for retrieval and to allow for the disambiguation of leaf names if they are not unique.

      NamedIDHierarchy is used primarily for identifying objects in the system that are not in the Connect Common Object Model (e.g., folders).

      For Parents (plural) I see the following text

      List of the parents of the entry, in order from root to immediate parent

      So it seems (not tested) to give you the complete path (from level 1 to the level you are in) so you may need to extract the level 1 only before you can assign it to the level 1 parent.

    • Nigel Oliver

      Thanks Sebastiaan,

      In the end we have returned the categories as an array and used in_array()

      // Get Cat list
      $aCatIds = array();
      if($incident->Category && $incident->Category->ID) {
      $aCatIds[] = $incident->Category->ID;
       
      foreach($incident->Category->CategoryHierarchy as $oCategory) {
      $aCatIds[] = $oCategory->ID;
      }
      }
       
      if (in_array(581, $aCatIds, true) {
      echo 'matched 586';
      }
       
      Cheers
       
      Nigel