Attachments

From AgileApps Support Wiki
Revision as of 10:28, 27 October 2016 by imported>Aeric

About Attachments

Attachements are files that are uploaded and "attached" to a Case or to a record in some other platform Object.

Considerations
  • All files are added to the Attachments object, except for the special file field that comes predefined as a part of the cases object. (A file uploaded to that field is stored as part of the record.)
  • When viewing Case details, a button button appears that lets you upload a file to that field.
  • As with any other file field, the field changes to show the file, when a file has already been uploaded.
  • In essence, that field defines a "primary" file that can be labeled and attached to a case.
  • However, unlike other file fields, anything uploaded to the default file field in the Cases object also appears in the list of Attachments that appears in the sidebar.
    (Files uploaded to other file fields do not appear there.)
  • So even if multiple files are added (using emails, for example), there is only ever one "primary" file associated with the case, and that file is displayed in the details area of the record.
  • A file added in the sidebar is a private attachment that is never visible to an external user. It is added directly to the Attachments object.
  • A file added in a Private Note or Email has a slightly different button:
  • A file added using that button also goes directly to the Attachments object.
  • If added in a Private Note, it is a private attachment that is never visible to an external user. It is only visible if it is added to an email, It is then a public attachment that does display in the service-portal file list that is visible to an external user.

Working with Attachments

Adding an Attachment

To add an attachment to a record:

  1. When viewing or creating a a Case record or some other record, under Attachment, click [Select a File].
  2. When adding Private Notes and Email Messages, click [Attach File].
  3. When viewing a record, under Files in the sidebar, click Add File.
  4. Fill in the Attachment Settings
  5. Click [Save]

Viewing Attachments

When viewing a a Case record or some other record, attachments are listed under Files in the sidebar.

Clicking an attachment lets you download it or view it immediately, depending on your Service Provider's networking.properties configuration. (In the cloud, attachments are viewed immediately.)

Attaching a file to a case

To attach a file to a case record using API:

import java.io.File;

import javax.ws.rs.core.MediaType;

import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.methods.multipart.FilePart;
import org.apache.commons.httpclient.methods.multipart.MultipartRequestEntity;
import org.apache.commons.httpclient.methods.multipart.Part;
import org.apache.commons.httpclient.methods.multipart.StringPart;

public class AttachmentUpload {

	public static void main(String[] args) {
		// TODO Auto-generated method stub

		System.out.println("HelloWorld");
		 try
	        {
	            File f = new File("C:\\Users\\Public\\Pictures\\Sample Pictures\\Desert.jpg");
	            
	            HttpClient client = new HttpClient();

	            //Add a record to a custom object called "Attachment"
	            PostMethod postMethod = new 
	                PostMethod("http://localhost/networking/rest/record/attachments");
	            
	            //Set the session for this request.
	            postMethod.setRequestHeader("Cookie", "JSESSIONID=22588C70A4D95CEA5FC75C2BBDCDA564");

	            //The first attribute of the FilePart constructor refers to the file field name 
                //ie.file_field 
	            FilePart filePart = new FilePart("file_field", f);
	            
	            //Set the content type of the filePart
	            filePart.setContentType(MediaType.APPLICATION_OCTET_STREAM);

	            //Create the xml part of the request
	            // __xml_data__ is required for the name attribute 
	            // If the content type is json, use __json_data__
	            StringPart sp = new StringPart("__xml_data__",
	              "<platform><record><title>Some text field</title>"
	            + "<file_field>Desert.jpg</file_field>"+
	            		  "<related_to type=\"0d35c4c4af094277bbf0321478f5207a\">1200255925</related_to></record></platform>");
	            
	            //Set the Content-type of the xml part
	            sp.setContentType(MediaType.APPLICATION_XML);
	            
	            final Part[] parts = { sp, filePart };

	            postMethod.setRequestEntity(new MultipartRequestEntity(parts, postMethod.getParams()));
	            
	            postMethod.addRequestHeader("Accept", "application/xml");
	            //System.out.println("Execute Method:");
	            int executeMethod = client.executeMethod(postMethod);
	            System.out.println("Execute Method:"+executeMethod);
	            
	            byte[] responseBody = postMethod.getResponseBody();

	            System.out.println(new String(responseBody));
	            
	            
	            
	            System.out.println("Execute Method:"+executeMethod);
	        }
	        catch(Exception e)
	        {
	            System.out.println("Exception"+e.getMessage());
	        }

	}

}