how to access Ticket that is not allowes in customer center

Hi,

I want to add new Message on a ticket but it redirect to the noaccess.html.

How can I add than a new Message (addMessage) to the ticket. Give it a workaround?

I have my own dialog but the idea was to use the addMessage function but it doesn't. any idea ?

%EJSCRIPT_START%
  <%
  #setLanguageLevel 3;

  String wwwRoot = getParserVariable("WwwRoot");
   
  String ticketID = getCgiVariable("ticketId");
  String projektID = getCgiVariable("projektId");

  //Search Ticket
  String ticketTitle;
  String ticketCreatedAt;
  String ticketCategory;
  String ticketStatus;

  SearchEngine seTicket;
  seTicket.setDBDistinct(true);
  seTicket.bypassNetServer(true);
  seTicket.addField("ticket.title");
  seTicket.addField("ticket.created_at");
  seTicket.addField("ticket.category.(ej_category->id).external_name");
  seTicket.addField("ticket.ticket_status.(ticket_status->id).name");
  seTicket.addCriteria("ticket.id", "Equals", ticketID, "And", 0);
  for (seTicket.execute();!seTicket.eof();seTicket.next()){
    ticketTitle=seTicket.getField(0);
    ticketCreatedAt=seTicket.getField(1);
    ticketCategory=seTicket.getField(2);
    ticketStatus=seTicket.getField(3);
  }

  //Search Message
  String messageID;
  String messageTitle;
  String messageCreatedAt;
  String messageAuthor;
  String messageMessage_id;
  String messageBody;
  String messageBodyHTML;
  String myMessageBody;

  SearchEngine seMessage;
  seMessage.setDBDistinct(true);
  seMessage.bypassNetServer(true);
  seMessage.addField("ej_message.id");
  seMessage.addField("ej_message.search_title");
  seMessage.addField("ej_message.created_at");
  seMessage.addField("ej_message.author");
  seMessage.addField("ej_message.message_id");
  seMessage.addField("ej_message.body");
  seMessage.addField("ej_message.html_body");
  seMessage.addCriteria("ej_message.ticket_id", "Equals", ticketID, "And", 0);
  
  %>
<html>
<head>
<title>Support | %IF:customerLang!="de"%
    Anfrage <%print(ticketID);%>:<%print(ticketTitle);%> 
     %ELSE%
    Anfrage <%print(ticketID);%>:<%print(ticketTitle);%> 
     %ENDIF%
  </title>
</head>
<body>
  <div id='listTicket'>
  <h2 class='page-header'>Anfrage <%print(ticketID);%>: <%print(ticketTitle);%></h2>
  <div class='row'>
    <div class="col-sm-6">
      <table class="table">
        <tr><td><strong>Erfasst</strong></td><td><%print(ticketCreatedAt.toDateTime().toString("DD2.MM2.YY4 HH24:MI2"));%></td></tr>
        <tr><td><strong>Kategorie</strong></td><td><%print(ticketCategory);%></td></tr>
        <tr><td><strong>Status</strong></td><td><%print(ticketStatus);%></td></tr>
      </table>
    </div>
  </div>
    <div id='messages'>
    <%
          Integer messageCount = 0;
for (seMessage.execute();!seMessage.eof();seMessage.next()){
          messageID=seMessage.getField(0);
          messageTitle=seMessage.getField(1);
          messageCreatedAt=seMessage.getField(2);
          messageAuthor=seMessage.getField(3);
          messageMessage_id=seMessage.getField(4);
          messageBody=seMessage.getField(5);
          messageBodyHTML=seMessage.getField(6);
          
          if(messageBodyHTML != ''){
            myMessageBody = messageBodyHTML;
          }
          else{
            myMessageBody = messageBody;
          }
            
          //Search Attachement
          Map mAttachement;
          String ticketAttachementID;

          SearchEngine seTicketAttachment;
          seTicketAttachment.setDBDistinct(true);
          seTicketAttachment.bypassNetServer(true);
          seTicketAttachment.addField("ticket_attachment.attachment_id");
          seTicketAttachment.addCriteria("ticket_attachment.message_id", "Equals", messageID, "And", 0);
          for (seTicketAttachment.execute();!seTicketAttachment.eof();seTicketAttachment.next()){
            ticketAttachementID = seTicketAttachment.getField(0);
            SearchEngine seAttachment;
            seAttachment.setDBDistinct(true);
            seAttachment.bypassNetServer(true);
            seAttachment.addField("attachment.name");
            seAttachment.addField("attachment.auth_key");
            seAttachment.addCriteria("attachment.id", "Equals", ticketAttachementID, "And", 0);
            for (seAttachment.execute();!seAttachment.eof();seAttachment.next()){
              mAttachement.insert(ticketAttachementID+"-"+seAttachment.getField(1),seAttachment.getField(0));
            }
          }
        
          Integer myPadding = 14 + messageCount*10;
          String smyPadding = myPadding.toString()+"px";
          if(messageCount > 0){
          %>
            <div class='myticketMessage' style='clear:left;border-top: 1px solid #e2e2e2; border-bottom: 1px solid #e2e2e2; background-color: #fffdf4; padding: 14px; padding-left:<%print(smyPadding);%>;'>
          <%  } else { %>
            <div class='myticketMessage' style='display:block'>
          <%}%>
               <img src='%AuthProgram%&action=printBin&customerId=%customer.id%.png' alt='Image' style='float: left; padding-right: 10px; padding-top: 4px;'/>
               <h4><span class='data'><%print(messageAuthor);%> - <%print(messageCreatedAt.toDateTime().toString("DD2.MM2.YY4 HH24:MI2"));%></span></h4>
                 <%print(myMessageBody.extractHtmlBody(true));%>
                 <% 
                   if(mAttachement.size() > 0){
                     %><ul class="attList"><%
                       while (!mAttachement.eof()){
                         String myRoot = "/scripts/customer.fcgi/getAttachment/";
                         String attach = mAttachement.getKey()+"-0/";
                         String title = mAttachement.getVal();
                         String urlParam = "?custSessionKey="+getParserVariable("CustSessionKey");
                         String url = myRoot+attach+title+urlParam;
                         %><li>
                           <a href='<%print(url);%>'><%print(title);%></a>
                           </li><%
                         mAttachement.next();
                       }
                     %></ul><%
                   }
                   
                  %>
            </div>
      <%
         messageCount = messageCount+1;
      }%>
      <div class='addMessage'>
         <img src='%WwwRoot%graphics/SevenCustomer/legg_til.png' alt='Nachricht hinzufügen'/> Nachricht hinzufügen
      </div>
      <div id='addMessageContainer'>
            <% 
               String actionUrl = getParserVariable("AuthProgram")+"&action=addMessage&ticketId="+ticketID+"&projektId="+projektID;
            %>
            <form name='mainForm' id='mainForm' method='post' enctype='multipart/form-data' action='<%print(actionUrl);%>' class="form-horizontal">
              <div id='messageContainer' class="col-md-12">
                <div class="row">
            <div class='form-group'>
              <div class="col-sm-12">
                <img src='%AuthProgram%&action=printBin&customerId=%customer.id%.png' alt='Image' style='float: left; padding-right: 10px; padding-top: 3px;'/>
                <label for='message' class='control-label'>%customer.name% schreibt:</label>
              </div>
            </div>
          </div>
                <div class="row">
                  <div class='form-group'>
                    <div class="col-sm-12">
                      <textarea class='editMessage form-control' name='message' id='message' rows="10"></textarea>
                    </div>
                  </div>
                </div> 
                <div class="row">
                  <div class="form-group">
                    <div class="col-sm-12">
                      <label id='fileUploadButton'><img src='%WwwRoot%graphics/SevenCustomer/vedlegg.png' alt='Anhang hinzufügen' title='Anhang hinzufügen' />  Anhang hinzufügen</label>
                      <div id='fileUpload' class='hidden'>
                        <ul id='fileList'>
                          <li><input type='file' name='attachment_' /><a class='remove hidden'><img alt='Anhang löschen' title='Anhang löschen' src='%WwwRoot%graphics/SevenCustomer/del.png'/></a></li>
                        </ul>
                      </div>
                    </div>
                  </div>
                </div>        
              </div>
              <div id='messageSend' style="clear:left;">
                <input type='submit' name='ok' value='Senden' class="btn btn-success" />
              </div>
              <span id='messageempty' class='error hidden'>Nachricht eingeben</span>          
           </form>
      </div>
    </div>
  </div>
  <script type="text/javascript">
    $(document).ready(function(){
      $('#fileUploadButton').on('click', function(){
        $('#fileUpload').removeClass("hidden");
      });
    });
  </script>                      
</body>
</html>
%EJSCRIPT_END%

RE: how to access Ticket that is not allowes in customer center

Hi,

If you want to be able to comment on tickets which is not connected to logged in customer, you cannot use built in functions as this has access control checks. To accomplish this you will need to create own functions to be able to comment on tickets. You might find some inspiration here.

By: Michel Krohn-Dale 17 Sep 2020