ALM12 Workflow - Count attachments of a new requirement
I am attempting to write workflow code to require a user to attach at least one file to a new requirement. Unfortunately, it appears that the attachment/s are not saved until after the Req_AfterPost sub has finished.
The following sub returns the correct number for existing Requirements, but returns 0 for new ones with attachments. The same code cannot be used in Req_CanPost for new requrements, as at that stage, the requirement does not have any id.
Sub Template_Req_AfterPost Dim ReqID, Requirement, AttList ReqID= Req_Fields("RQ_REQ_ID").value Set Requirement = TDConnection.ReqFactory.Item(ReqID) Set AttList = Requirement.Attachments.NewList("") Msgbox AttList.Count,,"Attachment Count" End Sub
Is there any way to check whether there are any attachments before the requirement record is saved?
We are using ALM 12.01
Unfortunately, the attachment reference for new items is not added to the database until after the AfterPost event occurs. It is the same in the other modules, unless it has changed recently.
You can't even rely on the Attachment_New event, since it is not triggered for new requirements, only for existing ones. I would call that a bug.
[Please do not contact me off line for receiving support. Use the forum!]
The closest I have been able to get to solving this is to track whether the user has pressed the attach button.
Function Template_ActionCanExecute(ActionName)is called when the file is attached to a new requirement, with the value "NewReqAttachment.AttachFile". I have not been able to find a way for the code to determine whether the user attached a file (as opposed to pressing the cancel button in the attach dialog).