This is a public Forum  publicRSS

Topic

    Amani Hanna
    CP2 to CP3: Fetch group ID from answer table
    Topic posted March 13, 2018 by Amani HannaJourneyer, last edited March 13, 2018 
    62 Views, 17 Comments
    Title:
    CP2 to CP3: Fetch group ID from answer table
    Content:

    Hi,

    I am trying to fetch the group id from the answer table to display on our answer view page. In the CP2 framework it seems that this would have worked by referring to the answers table (answers.assgn_group_id).

    I have tried to display the group id in the CP3 framework using the below code snippet but am running into an error:

    <rn:field name="Answer.assgn_group_id"/>
    

    Error with rn:field tag: Primary object Answer is not supported

    How would I retrieve the group id in the CP3 framework?

    Thanks.

    Version:
    Customer Portal 3.6
    Code Block:

    Answer

    • Gursimran Singh Saini

      Answer Group is not available in CP 3 Business Objects table.

      Check here: https://<interface>.custhelp.com/ci/admin/docs/framework/businessObjects

      Although 'Primary Object Answer is not supported' means you are trying to access Answer Business Object on a non-Answer page.
      Have you updated the <rn:meta> tag according to CP 3 specifications?
      It should look like this:

      <rn:meta title="#rn:php:\RightNow\Libraries\SEO::getDynamicTitle('answer', \RightNow\Utils\Url::getParameter('a_id'))#" template="standard.php" answer_details="true" clickstream="answer_view"/>

    • Amani Hanna
      Gursimran Singh Saini said:

      Answer Group is not available in CP 3 Business Objects table.

      Check here: https://<interface>.custhelp.com/ci/admin/docs/framework/businessObjects

      Although 'Primary Object Answer is not supported' means you are trying to access Answer Business Object on a non-Answer page.
      Have you updated the <rn:meta> tag according to CP 3 specifications?
      It should look like this:

      <rn:meta title="#rn:php:\RightNow\Libraries\SEO::getDynamicTitle('answer', \RightNow\Utils\Url::getParameter('a_id'))#" template="standard.php" answer_details="true" clickstream="answer_view"/>

      View original

      Thank you for the quick response and for the documentation.

      Is there another way to reference the managing owner of the article on our answer view page?

      The meta tag looks like this currently:

      <rn:meta title="#rn:php:\RightNow\Libraries\SEO::getDynamicTitle('answer', \RightNow\Utils\Url::getParameter('a_id'))#" template="ampf_okcs_standard.php" clickstream="answer_view"/>
      

      When I add the answer_details="true" part, I get redirected to app/error/error_id/1

    • Gursimran Singh Saini

      You get redirected to error page because you are not allowed to access that Answer.
      Check here to find out why you are not able to access the Answer: https://cx.rightnow.com/app/answers/detail/a_id/9125

      Regarding Answer Group/Account, you have to use Connect PHP API. Quick, easy.

    • Amani Hanna
      Gursimran Singh Saini said:

      You get redirected to error page because you are not allowed to access that Answer.
      Check here to find out why you are not able to access the Answer: https://cx.rightnow.com/app/answers/detail/a_id/9125

      Regarding Answer Group/Account, you have to use Connect PHP API. Quick, easy.

      View original

      I referred to the Connect PHP API guide to attempt to fetch this data, but am seeing an error with my query.

      Here's my code snipped on how I'm trying to access the owner of the content:

        function getAccountInfo($aid){
              $owner = RNCPHP\Account::fetch(1);
              return $owner;
          }
      
      $owner = $this->model('custom/Contact_Model')->getAccountInfo(\RightNow\Utils\Url::getParameter('a_id'));
          print_r("assigned to: ".$owner."\n");
      

      Here's the error:

      A PHP Error was encountered

      Severity: 4096

      Message: Object of class RightNow\Connect\v1_2\Account could not be converted to string

      Here's the documentation I'm referring to.

      http://documentation.custhelp.com/euf/assets/devdocs/august2017/Connect_PHP/Content/Connect%20for%20PHP%20API/RightNow%20Connect%20Object%20Model/Core/GroupAccount.html 

    • Gursimran Singh Saini

      Try this:

      $answer = RightNow\Connect\v1_3\Answer::fetch(getUrlParm('a_id'));
      if($answer->AssignedTo->Account){
          $answerAssignedAccount = $answer->AssignedTo->Account->Name;
      }

    • Amani Hanna
      Gursimran Singh Saini said:

      Try this:

      $answer = RightNow\Connect\v1_3\Answer::fetch(getUrlParm('a_id'));
      if($answer->AssignedTo->Account){
          $answerAssignedAccount = $answer->AssignedTo->Account->Name;
      }

      View original

      Here is the error I am receiving now:

      Fatal error: Uncaught exception 'RightNow\Connect\v1_3\ConnectAPIError' with message 'Invalid ID: No such Answer with ID = 182738'

    • Gursimran Singh Saini

      Do you have an Answer with ID 182738?

      Is this ID shown next to a_id parameter in this page URL?

    • Amani Hanna
      Gursimran Singh Saini said:

      Do you have an Answer with ID 182738?

      Is this ID shown next to a_id parameter in this page URL?

      View original

      Yes to both. 

    • Gursimran Singh Saini

      Hmm interesting. Not sure why this is happening.
      Only possible reason can be that Answer with this ID isn't available.

      There's another way to access Answer data through Standard CP Models.

      Try this:
      $this->load->Model('Answer');
      $answer = $this->Answer->get(getUrlParm('a_id'));
      if($answer->AssignedTo->Account){
          $answerAssignedAccount = $answer->AssignedTo->Account->Name;
      }

    • Amani Hanna
      Gursimran Singh Saini said:

      Hmm interesting. Not sure why this is happening.
      Only possible reason can be that Answer with this ID isn't available.

      There's another way to access Answer data through Standard CP Models.

      Try this:
      $this->load->Model('Answer');
      $answer = $this->Answer->get(getUrlParm('a_id'));
      if($answer->AssignedTo->Account){
          $answerAssignedAccount = $answer->AssignedTo->Account->Name;
      }

      View original

      I have tried on multiple answer IDs so I am not sure if that's the case. 

      I tried the above code and it is resulting in the following error.

      Fatal error: Call to a member function Model() on null 

    • Gursimran Singh Saini

      Could you please test the Connect PHP code in a Custom Script?

      See if you are able to access any Answer in a Custom Script.

      It might be a permissions issue.

    • Amani Hanna
      Gursimran Singh Saini said:

      Could you please test the Connect PHP code in a Custom Script?

      See if you are able to access any Answer in a Custom Script.

      It might be a permissions issue.

      View original

      What is meant by a custom script? We have created a custom model to retrieve Contact data, so in the same way we are trying to retrieve Answer data. Are you referring to something different?

    • Gursimran Singh Saini

      I am referring to PHP Scripts that can be hosted in File Manager.
      You can open File Manager through Configuration -> Site Configuration

      For more info: http://documentation.custhelp.com/euf/assets/devdocs/cloud18a/olh/CoreFeatures/topicrefs/c_File_Manager_directories_bi1133483.html?hl=custom%2Cscript

    • Rajan Davis
      You will need to build a custom widget and update your code; please follow these steps:
       
      I. Building a Custom Widget
      1.  Go to https://<yoursite>/ci/admin/tools/widgetBuilder; you will need to log in with admin credentials.
      2.  Click on "Create a brand new widget from scratch"
      3.  Name your widget whatever you want (eg. AnswerAssignedOutput) and name the folder (eg. output) that you want your widget to reside in
      4.  Click "Yes" for the question "Does this widget have a controller?"
      5.  Click "Yes" for the question "Does this widget have a view?"
      6.  Click "Continue"
      7.  Click "Continue" again
      8.  Click "Create Widget"
       
      II. Updating your code
      9.  Login into a WebDAV Client
      10. Navigate to the "/dav/cp/customer/development/views/pages/answers" folder
      11. Open the "detail.php" page
      12. Add the following code:
      <div>
          <rn:widget path="custom/output/AnswerAssignedDisplay"/>
      </div>
      
      13. In the WebDAV Client, navigate to the "/dav/cp/customer/development/widgets/custom/<folder of you custom widget>/<name of your widget>/1.0"
      14. Open the "controller.php" and "view.php" files
      15. Place the following code in the "controller.php":
       
      <?php
      
      // The last portion of this needs to match the folder name
      
      namespace Custom\Widgets\output;
      
      use RightNow\Connect\v1_3 as RNCPHP;
      
      
      // This classname MUST match the name of your widget
      
      class AnswerAssignedDisplay extends \RightNow\Libraries\Widget\Base {
      
          function __construct($attrs) {
      
              parent::__construct($attrs);
      
          }
      
      
          function getData() {
      
              $query = "SELECT answer.AssignedTo.StaffGroup.ID as id,answer.AssignedTo.StaffGroup.LookupName as name FROM answer WHERE ID = " . getUrlParm('a_id');
      
              $query_results = RNCPHP\ROQL::query($query)->next();
      
              $answer_assigned_group = array();
      
              while($res = $query_results->next()) {
      
                  array_push($answer_assigned_group, $res);
      
              }
      
      
              $this->data['answer_assigned_group'] = $answer_assigned_group[0];
      
          }
      
      }
      
       
       
      16. Place the following code in the "view.php":
      <div id="rn_<?= $this->instanceID ?>" class="<?= $this->classList ?>">
          <p><?=$this->data['answer_assigned_group']['name']?></p>
          <p><?=$this->data['answer_assigned_group']['id']?></p>
      </div>
      
       
      17. To preview these changes in the browser, please navigate to https://<yoursite>/ci/admin/overview/set_cookie/development
              a. you may need to log in 
      18. Once you have logged into the development portion of your site, navigate to an answer page; the widget should display the information you are looking for
       
      If you have any questions on the above, feel free to ask.
    • Suresh Thirukoti

      Oh Rajan again!! Are you super typer or built some kind of ruby on rails stuff to do it for you..........wink..anyway nice read