Delete

Description

Deletes an attached file from the collection.

For VBScript, the argument to this method can be either a numeric index (itemNum) or a display name (displayName). For Perl, the argument must be a numeric index.

You can use the Count and Item methods to locate the correct Attachment object before calling this method.

Note: The Entity must be in an editable state before calling the Delete method. If you are using this method in a HCL Compass hook and you are deleting an attachment from the current record (that is, the record upon which the current action is in progress), then the entity is already in an editable state. However, if you are using this method in a hook and deleting an attachment from a record other than the current entity, or if you are using this method in an external program, you must first put the entity into editable state by calling the EditEntity method. See the EditEntity method for more information.

Syntax

VBScript


attachments.Delete itemNum 
attachments.Delete displayName 

Perl


$attachments->Delete(itemNum); 
Identifier
Description
attachments
An Attachments collection object, representing the set of attachments in one field of a record.
itemNum
For VBScript, a Variant that is an index into the collection. This index is 0-based and points to the file that you want to delete. For Perl, a Long that is an index into the collection. This index is 0-based and points to the file that you want to delete.
displayName
For VBScript a Variant that is a display name of an item in the collection.
Return value
A Boolean that is True if the file was deleted successfully, otherwise False.

Examples

VBScript

' This example assumes there is at least 1 attachment field in this record type,
' and at least one attachment associated with this record.
' NOTE: The entity must be in an editable state to delete an attachment -- see above.
set currentSession = GetSession
set attachFields = AttachmentFields
set attachField1 = attachFields.Item(0)
set theAttachments = attachField1.Attachments
If Not theAttachments.Delete(0) Then
    OutputDebugString "Error deleting the attachment."
End If

Perl

# This example assumes there is at least 1 attachment field in this record type,
#  and at least one attachment associated with this record.
# NOTE: The Entity must be in an editable state to delete an attachment -- see above.
# For this entity record, get the collection of all attachment fields
$attachfields = $entity->GetAttachmentFields();
# Work with the first attachment field
$attachfield1 = $attachfields->Item(0);
# For this attachment field, get the collection of all its attachments
$attachments = $attachfield1->GetAttachments();
# Delete the first attachment
if (!$attachments->Delete(0)) {
    $session->OutputDebugString("Error deleting attachment from record.\n");
}