JavaScript method: SCFile.insertAttachment( attachObj )

This method creates a new attachment associated with the current file record. Before calling insertAttachment, you must establish a current record using one of the positioning methods, such as doSelect(), getNext(), etc.

Syntax

SCFile_object.insertAttachment( attachObj );

Arguments

The insertAttachment method takes one argument, which is an asttachment object.

The Attachment object must be properly populated prior to calling insertAttachment.

Attachment objects can be obtained via Web Services calls or constructed by JavaScript code.

Required properties

Attachment.name: This is a string containing the name of the attachment, for example, foo.txt or foo.pdf.

Attachment.type: This is a string containing the MIME type of the attachment, such as text/plain or application/pdf.

Attachment.value: This is a binary string containing the actual attachment data. One way to obtain such data is by using the readFile() global method with the binary file format (readFile(path,"b")).

The "href" property of the attachment object should not be set for an insert operation. Any value supplied will be ignored. Attachment ID values are assigned by the server when attachments are inserted or updated.

Return values

If successful, insertAttachment() returns a string of the form cid:xxxxxx containing the attachment ID for the inserted attachment.

Example

This example does the following:

  • Creates a new attachment object
  • Selects one record from the probsummary table
  • Inserts the attachment object to the current record

This example requires the following sample data:

  • Record number IM10001 in the probsummary table

var attachmentObj = new Attachment();

attachmentObj.type   = "text/plain";
attachmentObj.name  = "MyAttachment.txt";
attachmentObj.value = "This is a test text attachment";

var f = new SCFile( 'probsummary' );

var rc = f.doSelect( 'number = "IM10001"' );

var attachmentID = f.insertAttachment( attachmentObj );