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
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
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
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
Note: I can ADD a new attachment. Sigh.
WO.AddAttachmentFieldValue "Attachments" , "C:\YServer.txt", "KathyFile" ' !!!!! This works!
Pinned topic [clearquest] Attachment APIs in scripts - not getting anywhere
Answered question This question has been answered.
Unanswered question This question has not been answered yet.
Updated on 2009-05-04T22:59:34Z at 2009-05-04T22:59:34Z by BobD
Leesa_Hicks 1200009HC4269 Posts
Re: [clearquest] Attachment APIs in scripts - not getting anywhere2009-04-29T19:47:52ZThis is the accepted answer. This is the accepted answer.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.
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
BobD 120000HN9V202 Posts
Re: [clearquest] Attachment APIs in scripts - not getting anywhere2009-05-04T22:59:34ZThis is the accepted answer. This is the accepted answer.
- Leesa_Hicks 1200009HC4
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.