JavaScript global method: writeAttachmentToFile

Writes a requested attachment record to the local file system.

Syntax

writeAttachmentToFile( File, Application, Topic, UID );

Arguments

The following arguments are valid for this method:

Name Data type Required Description
File String Yes

This argument specifies the file name of the attachment you want to write out to the file system. You may also use this argument to specify the destination path of the attachment. If this argument does not specify a path, Service Management creates the attachment in the system working directory.

Application String Yes This argument specifies the application name portion of the key that Service Management uses to identify the attachment in the SYSATTACHMENTS table.
Topic String Yes This argument specifies the topic name portion of the key that Service Management uses to identify the attachment in the SYSATTACHMENTS table.
UID String Yes This argument specifies the unique identifier portion of the key that Service Management uses to uniquely identify the attachment in the SYSATTACHMENTS table.

Return values

RC_SUCCESS or one of the other global return code values.

The method writes the attachment record specified in the method arguments to the local file system and returns a global return code value of RC_SUCCESS or returns one of the failure global return code values if the method cannot return an attachment record.

Description

This method extracts the specified attachment from the SYSATTACHMENTS table and writes it to the specified file and path on the local file system.

Note If you specify a path, you must escape out any JavaScript reserved-characters in the path name such as slashes and backslashes. Consult a JavaScript reference for a full list of JavaScript reserved-characters and escape methods.

Example

This example does the following:

  • Requests an attachment from the SYSATTACHMENTS table
  • Writes the attachment to the file c:\kmdocument.pdf
  • Prints the return code to the screen

This example requires the following sample data:

  • The Knowledge Management record KM0018
  • An attachment in KM0018
var rc;
rc = writeAttachmentToFile( "c:\\kmdocument.pdf", "kmdocument", "KM0018", "4462590a062ee0c2101d85c8" );
if ( rc == RC_SUCCESS )
{
 print( "kmdocument.pdf successfully created" );
}
else
{
 print( "kmdocument.pdf failed " , RCtoString(rc) );
}