Integrations and APIs for Service

Get Involved. Join the Conversation.


    Vincent McCarthy
    Reading the contents of an incident attachment in an add-in
    Topic posted August 2, 2012 by Vincent McCarthyGreen Ribbon: 100+ Points, last edited August 3, 2012 
    413 Views, 3 Comments
    Reading the contents of an incident attachment in an add-in



    I am writing a custom add-in that takes a lot of information about an incident and then creates a PDF to send to another system. I am a bit stumped as to how to read the contents of attachments though?

    Is there something obvious that I'm missing. Any tip to put me in the right direction would be hugely appreciated.

    Here's what I have so far:

                var currentIncident = (IIncident)_recordContext.GetWorkspaceRecord(WorkspaceRecordType.Incident);
                var rnAttachments = currentIncident.FAttach2;
                foreach (IFAttachInc2 att in rnAttachments)
                    // how do I get the content. Seems to only be information about the attachment - content type and size etc???




    feb 2012



    • Vincent McCarthy

      Also if I could add to the above,

      Is it possible to somehow read the attachments associated with a response or customer query threads in the messages tab




    • Pathaksa Tongpitak

      Hi Vince,


      Hopefully this code will help you:



              public FileAttachmentIncident[] copyAttachments(Incident incidentSource)

                  List<FileAttachmentIncident> fileAttachments = new List<FileAttachmentIncident>();
                  if (incidentSource.FileAttachments != null)
                      foreach (FileAttachmentCommon f in incidentSource.FileAttachments)
                          fileAttachments.Add(createFileAttachment(f, incidentSource));

                      return fileAttachments.ToArray();
                      return null;
              public FileAttachmentIncident createFileAttachment(FileAttachmentCommon f, Incident incidentSource)
                  FileAttachmentIncident fa = new FileAttachmentIncident();

                  fa.action = ActionEnum.add;
                  fa.actionSpecified = true;

                  fa.ContentType = f.ContentType;
                  fa.Data = GetFileData(f.ID, incidentSource, f);

                  debugLog += + " = " + f.ContentType + Environment.NewLine;
                  fa.Description = f.Description;
                  fa.FileName = f.FileName;
                  fa.Name = f.Name;
                  return fa;
              public byte[] GetFileData(ID fileID, Incident incident, FileAttachmentCommon file)
                  ClientInfoHeader clientInfoHeader = new ClientInfoHeader();

                  clientInfoHeader.AppID = "Query Example";

                  byte[] fileData = _client.GetFileData(clientInfoHeader, incident, fileID, false);

                  return fileData;

    • Vincent McCarthy

      Hi Pathaksa

      Yes that's very helpful thank you. I tried the GetFileData method in a service last week but wasn't getting it to work. (I wasn't passing in the concrete incident as you do in this case). I imagine what I'll do is to get the add in to call the RightNow Service that will retrieve these attachments.