JavaScript method: SCFile.updateAttachment( attachObj )

This method updates a specific attachment associated with the current file record. The attachment object must contain a valid attachment ID in the "href" property of the attachment object, as well as valid values for the other required properties (name, type, and value). Before calling updateAttachment, you must establish a current record using one of the positioning methods, such as doSelect(), getNext(), etc.

Syntax

SCFile_object.updateAttachment( attachObj );

Arguments

updateAttachment() takes one argument, which is an Attachment object.

Return values

If successful, updateAttachment() returns a string of the form cid:xxxxxx containing the new attachment ID for the attachment. Otherwise, it returns NULL.

Example

This example does the following:

  • Selects one record from the probsummary table
  • Gets a specific attachment associated with the current record
  • Updates the attachment

This example requires the following sample data:

  • "IM10001" record in "probsummary" table
  • An attachment associated with "IM10001" record
				
function createTestAttachment()
{
  var attachmentObj = new Attachment();

  attachmentObj.type  = "text/plain";
  attachmentObj.name  = "MyAttachment.txt";
  attachmentObj.value = "My text attachment";

  var f = new SCFile( 'probsummary' );
  
  var rc = f.doSelect( 'number = "IM10001"' );
  
  var attachmentID = f.insertAttachment( attachmentObj );  

  return attachmentID;
}

var attachmentID = createTestAttachment();

var f = new SCFile( 'probsummary' );
var rc = f.doSelect( 'number = "IM10001"' );
var attachmentObj = f.getAttachment( attachmentID ); 

// Now update the attachment object

var newName = "NewName.text";
var newValue = "Updated attachment text value";

attachmentObj.name = newName;
attachmentObj.value = newValue;

// Do the update. This should result in a new attachment ID

var newID =  f.updateAttachment( attachmentObj );