JavaScript object: Attachment

The following JavaScript object is unique to ITSMA Service Management. This object allows you to create attachments for use with doSOAPRequest methods. You have to manually define the value property of each attachment object. For binary data attachments, you can use the readFile global method to assign the value property. If you need to create multiple attachments for a doSOAPRequest request, you can use the push method to add each Attachment object to a JavaScript array.

Constructor

new Attachment();

Arguments

None

Properties

The following properties are valid for this object:

Property Data type Description
value Binary or String Use this property to store the binary or string data of the attachment.
len Integer This property contains the file size of the attachment in bytes.
href String Use this property to store the unique identifier for the attachment in the SOAP request message.
action String Use this property to store the name of action to take with the attachment in the Service Management Web Services API. The following options are available:
  • add – adds the specified attachment
  • remove – removes the specified attachment
  • get – retrieves the specified attachment
  • update – updates the specified attachment
name String Use this property to store the file name of the attachment.
type String Use this property to store the MIME type of the attachment.
attachmentType String Use this property to store the attachment type as defined in Service Management. If present and the property has a value of "img," then the attachment must also have a MIME type of "image/gif".
stringValue String This is a read only property.
When the attachment object contains a text value (utf-8 or ascii characters), user can use this property to get the string data of the attachment. The obtained string date then can be printed, concatenated, etc.

Methods

None

Example

    This example does the following:

  • Assume there are two attachments in the incident IM10005
  • Get the existing attachments from the IM10005
  • Concatenate these two attachments to a string
  • Create a new attachment which contains the concatenated string value
  • Insert MyAttachment.txt into IM10005 as a new attachment

This example requires the following sample data:

  • A binary file (for example, an image)
var f = new SCFile( 'probsummary' );    
var rc = f.doSelect( 'number = "IM10005"' );
var attachmentObj = f.getAttachments();
var str = "";
for ( var attachment in attachmentObj )     
{
print("Attachment Name:  "+ attachmentObj[ attachment ].name );
print("Attachment Value:  "+ attachmentObj[ attachment ].stringValue );
print("Attachment Value Length:  "+ attachmentObj[ attachment ].stringValue.length );
print("Attachment HREF:  "+ attachmentObj[ attachment ].href );
print("Attachment Type:  "+ attachmentObj[ attachment ].type); 
str+= attachmentObj[ attachment ].stringValue ;  
}   
//Create new attachment with a concatenated value
print("String Length:  "+str.length);      
var attachObj = new Attachment(); 
attachObj.type  = "text/plain";
attachObj.name  = "MyAttachment.txt";
attachObj.value = str;
var attachmentID = f.insertAttachment( attachObj );
print("AttachmentID:   "+attachmentID);