2 replies Latest Post - ‏2009-05-04T22:59:34Z by BobD
202 Posts

Pinned topic [clearquest] Attachment APIs in scripts - not getting anywhere

‏2009-04-29T18:05:25Z |
Can't seem to Delete or Edit Attachments. SR5 Windows. I can see everything, just can't get the syntax to work correctly. I hope I'm doing something obviously stupid - those are the easiest to fix!

I do the query and get the proper file name for the attachment, as seen in the Attachment control "blah blah.txt". However, it just won't delete it. No failure message, but record not updated with anything.

DIM WOAttachmentFields ' The list of attachment fields
DIM Field_Attachment ' An attachment field (contains a list of attachments)
DIM ActualAttachment ' The Attachment object in question
Dim FoundAttachmentFields

status = CQResultSet.MoveNext

Set WO = oSession.GetEntity("Work_Order",CQResultSet.GetColumnValue(1))
oSession.EditEntity WO, "AdminModify"

set WOAttachmentFields = WO.AttachmentFields
set Field_Attachment = WOAttachmentFields.Item(0) ' WO only has one Attachment-Type field - Attachments
set ActualAttachment = Field_Attachment.Attachments
set FoundAttachmentFields = ActualAttachment.Item(0) ' There are two attachments on this WO/Defect - only working with first
MsgBox "Attachment file name: " & FoundAttachmentFields.FileName
WO.DeleteAttachmentFieldValue Field_Attachment.Fieldname,FoundAttachmentFields.FileName
When I change it from Delete to simply try to edit the attachment description, I actually get a failure message:

' WO.DeleteAttachmentFieldValue Field_Attachment.Fieldname,FoundAttachmentFields.FileName

description = FoundAttachmentFields.Description
MsgBox description & " first" ' This shows properly
description = description & "Chg_04_27_09"
WO.EditAttachmentFieldDescription Field_Attachment.Fieldname,FoundAttachmentFields.FileName, description

Failure =WO.Validate
MsgBox "Failed ? " & Failure

ERROR MESSAGE from the above msgbox statement

Failed ? These fields have invalid values:
This value is not a properly formatted attachment description:

WO 0120 - 02/25/09Chg_04_27_09

OK Button

Note: I can ADD a new attachment. Sigh.
WO.AddAttachmentFieldValue "Attachments" , "C:\YServer.txt", "KathyFile" ' !!!!! This works!

Kathy Kopczynski
Updated on 2009-05-04T22:59:34Z at 2009-05-04T22:59:34Z by BobD
  • Leesa_Hicks
    269 Posts

    Re: [clearquest] Attachment APIs in scripts - not getting anywhere

    ‏2009-04-29T19:47:52Z  in response to BobD
    You might try using the Entity object methods for adding, deleting, and modifying attachments instead. It may be easier depending on what you are trying to do.

    Otherwise try performing the delete using the Attachments object. Field_Attachment.Attachments returns an Attachments object, which is the collection of the attachments in your attachments field. You'll need to determine which actual attachment need to be deleted.

    Dim ActualAttachments

    set ActualAttachments = Field_Attachment.Attachments

    ' You can supply either the item number or the display name - the following example uses the item number.
    if Not ActualAttachments.Delete(0) Then
    ' report an error
    End If
    Leesa Hicks
    • BobD
      202 Posts

      Re: [clearquest] Attachment APIs in scripts - not getting anywhere

      ‏2009-05-04T22:59:34Z  in response to Leesa_Hicks
      Does anyone have a working VBScript version of attachment deletion?

      I've tried the Entity deletion approach and the Attachment Object deletion approach, and have gotten nowhere. So it either doesn't work, or I've got a dumb typo somewhere in my code.

      The message box correctly displays the attachment info. But the Delete fails and the attachment remains.

      Since the coding markup doesn't seem to work, at least in preview, see
      attached RTF version of this code.