Skip Navigation
Retrieving data from objects using ROQL
Answer ID 6734   |   Last Review Date 12/18/2018

Do you have an example of php code retrieving a primary object that contains arrays using ROQL?


Oracle B2C Service, November 2011 and newer


Below is sample php code that demonstrates how to retrieve data in a primary object that contains arrays.

Your code may look different for authorization, and functionality. The code below will walk the primary object ServiceCategory and enumerate the values in all arrays that are available to ROQL.


require_once( get_cfg_var("doc_root")."/ConnectPHP/Connect_init.php");
initConnectAPI('userID','password');  (version November 2014 and newer - userID and password are no longer required on this line)

use RightNow\Connect\v1_2 as RNCPHP;

echo "<p>Service Category Object Test</p>";

try {
$queryResult = RNCPHP\ServiceCategory::fetch(ID);
echo "<p>This is the query Result</p>";

$cat = RNCPHP\ServiceCategory::fetch(ID);

$queryResult1 = RNCPHP\ROQL::queryObject("SELECT ServiceCategory FROM ServiceCategory where ID = 6")->next();
echo "<p>This is the query Result 1</p>";

$cat = $queryResult1->next();

         echo "<p>+++++++Simple Fields first:+++++++++++</p>";
           echo "<p>ServiceCategory Record ID:".$cat->ID."</p>";
              echo "<p>ServiceCategory LookupName:".$cat->LookupName."</p>";
           echo "<p>DisplayOrder:".$cat->DisplayOrder."</p>";
           echo "<p>Name:".$cat->Name."</p>";

                 echo "<p>++++++++++Admin Visible Interfaces:++++++++++++</p>";
                 $infnumb = count($cat->AdminVisibleInterfaces);
                  echo "<p>Count:".$infnumb."</p>";
                    for ($i = 0; $i < $infnumb; $i++) {
                    echo "<p>ID:".$cat->AdminVisibleInterfaces[$i]->ID."</p>";
                    echo "<p>Name:".$cat->AdminVisibleInterfaces[$i]->LookupName."</p>";

           echo "<p>+++++++++++++++Category Links:++++++++++++++++</p>";
                  $linknumb = count($cat->CategoryHierarchy);
                    echo "<p>Count:".$linknumb."</p>";
                    for ($i = 0; $i < $linknumb; $i++) {
                    echo "<p>ID:".$cat->CategoryHierarchy[$i]->ID."</p>";
                    echo "<p>Name:".$cat->CategoryHierarchy[$i]->LookupName."</p>";

           echo "<p>++++++++++++++++Descriptions:++++++++++++++</p>";
                  $descnumb = count($cat->Descriptions);
                    echo "<p>Count:".$descnumb."</p>";
                    for ($i = 0; $i < $descnumb; $i++) {
                    echo "<p>Label Text:".$cat->Descriptions[$i]->LabelText."</p>";
                    echo "<p>Name:".$cat->Descriptions[$i]->Language->LookupName."</p>";

           echo "<p>+++++++++++++++++EndUserVisibleInterfaces:++++++++++++</p>";
                   $euvinumb = count($cat->EndUserVisibleInterfaces);
                    echo "<p>Count:".$euvinumb."</p>";
                    for ($i = 0; $i < $euvinumb; $i++) {
                    echo "<p>ID:".$cat->EndUserVisibleInterfaces[$i]->ID."</p>";
                    echo "<p>Name:".$cat->EndUserVisibleInterfaces[$i]->LookupName."</p>";

           echo "<p>++++++++++++++++++++Names:++++++++++++++++++++++</p>";
                      $namesnumb = count($cat->Names);
                    echo "<p>Count:".$namesnumb."</p>";
                    for ($i = 0; $i < $namesnumb; $i++) {
                     echo "<p>Label Text:".$cat->Names[$i]->LabelText."</p>";
                    echo "<p>Name:".$cat->Names[$i]->Language->LookupName."</p>";

           echo "<p>++++++++++++++++++++Parent:+++++++++++++++++++</p>";
                 $parentnumb = count($cat->Parent);
                    echo "<p>Count:".$parentnumb."</p>";
                    for ($i = 0; $i < $parentnumb; $i++) {
                     echo "<p>Name:".$cat->Parent[$i]->Name."</p>";
                    echo "<p>Parent ID:".$cat->Parent[$i]->Parents."</p>";

           echo "<p>+++++++++++++++Product Hierarchy:+++++++++++++++++</p>";
                  $productnumb = count($cat->ProductLinks);
                    echo "<p>Count:".$productnumb."</p>";
                    for ($i = 0; $i < $productnumb; $i++) {
                     echo "<p>Name:".$cat->ProductLinks[$i]->ID."</p>";
                    echo "<p>Parent ID:".$cat->ProductLinks[$i]->LookupName."</p>";

catch (Exception $err ){    
echo $err->getMessage();}