Customer Portal

Get Involved. Join the Conversation.

Topic

    chidambaram CT
    Get incident attachments in CPAnswered
    Topic posted August 22, 2019 by chidambaram CTBronze Trophy: 5,000+ Points 
    42 Views, 7 Comments
    Title:
    Get incident attachments in CP
    Summary:
    Get incident attachments in CP
    Content:

    Hi All,

    I am try to get the incident attachments using the connect PHP refer my below code but i get error, can any one please assist me to get the incident attachments

    $incident = RNCPHP\Incident::fetch(6566);
    // print_r($incident->FileAttachments[0]->URL);
    $file_contents = file_get_contents($incident->FileAttachments[0]->URL);
    print_r($file_contents);
    // for ($i = 0; $i <= (count($incident->FileAttachments) - 1); $i++) {
    // $url = $incident->FileAttachments[$i]->getAdminURL();
     
    // }

     

    Error 
    Fatal error: Access to file_get_contents is denied because its trying to access restricted folders in /cp/customer/development/controllers/AjaxCustom.php on line 780
    Fatal error: Access to file_get_contents is denied because its trying to access restricted folders in /cp/customer/development/controllers/AjaxCustom.php on line 780
     

    Version:
    3.7

    Best Comment

    Tushar Gupta

    Hi Chidambaran,

    This would help you:

    <?php
              initConnectAPI('Username', 'Password');
              for ($i = 0; $i < count($result); $i++) {
                $orn1 = 123456;
                $opp = RightNow\Connect\v1_3\Opportunity::fetch($orn1);

                for ($k = 0; $k < count($opp->FileAttachments); $k++) {
                  $file_id = $opp->FileAttachments[$k]->ID;
                  $file1 = $result[$i]["File Attachment ID"];
                  if ($file_id == $file1) {
                    $url = $opp->FileAttachments[$k]->getAdminURL();
                    $file_id1 = $opp->FileAttachments[$k]->ID;
                    $fileName = $opp->FileAttachments[$k]->FileName;
                    $contentType = $opp->FileAttachments[$k]->ContentType;
                  }
                }
                ?>
              <?php } ?>

     This would give you all the attachments for the Opportunity.

    Comment

     

    • Tushar Gupta

      Hi,

      User Authentication is required. Pass Username and Password in the below before fetching the attachments:

      initConnectAPI(Username, Password);

      Thanks

    • chidambaram CT

      Hi Tushar,

      Can you please provide any example code.

      Thanks.

      • Tushar Gupta

        Hi Chidambaran,

        This would help you:

        <?php
                  initConnectAPI('Username', 'Password');
                  for ($i = 0; $i < count($result); $i++) {
                    $orn1 = 123456;
                    $opp = RightNow\Connect\v1_3\Opportunity::fetch($orn1);

                    for ($k = 0; $k < count($opp->FileAttachments); $k++) {
                      $file_id = $opp->FileAttachments[$k]->ID;
                      $file1 = $result[$i]["File Attachment ID"];
                      if ($file_id == $file1) {
                        $url = $opp->FileAttachments[$k]->getAdminURL();
                        $file_id1 = $opp->FileAttachments[$k]->ID;
                        $fileName = $opp->FileAttachments[$k]->FileName;
                        $contentType = $opp->FileAttachments[$k]->ContentType;
                      }
                    }
                    ?>
                  <?php } ?>

         This would give you all the attachments for the Opportunity.

    • chidambaram CT

      Hi Tushar,

      Great working fine thank you so much.

       

    • chidambaram CT

      Working code is below

       

      initConnectAPI('Username', 'Password');//AD credentials goes here
      $incidentid = ***;
      $incident = RNCPHP\Incident::fetch($incidentid);
      for ($k = 0; $k < count($incident->FileAttachments); $k++) {
      echo '<a href="'. $incident->FileAttachments[$k]->getAdminURL().'">'. $incident->FileAttachments[$k]->FileName.'</a><br>';
      $file_id1 = $incident->FileAttachments[$k]->ID;
      $fileName = $incident->FileAttachments[$k]->FileName;
      $contentType = $incident->FileAttachments[$k]->ContentType;
      }
    • Guru Jay

      getAdminURL() is not a multi-session call. Oracle strongly recommends not to use this based on my experience and this method is already in the path of deprecation.

       

      To get the file content, use  "https://xxxxxxx.custhelp.com//services/rest/connect/v1.x/incidents/" + your_IncidentId + "/fileAttachments/Your_attachment_ID?download". Then use XHR jscript method to get the data returned and construct blob object. Then from the blob object, you can create the href using.. window.URL.createObjectURL(blob) and this will be a clickable downloadable link.