Hi,
This Javascript:
app.execMenuItem("ShowHideFileAttachment");
will toggle the attachment panel open / closed.
If you put this in an early event (Form: Ready, Initialise) then if the form is saved with the attachment panel open, then the script will close it.
Because of this I don't see much value in tracking if new documents are attached, because the one script shows and hides the panel alternatively.
On one project we included a numeric field that showed the number of documents that were attached and if this was greater than 0, then a paperclip button was visible (with app.execMenuItem("ShowHideFileAttachment"); in the click event).
The numeric script looked like:
var oObj = event.target;
var fileAttachments = oObj.dataObjects;
if (fileAttachments != null)
{
this.rawValue = fileAttachments.length;
}
if (this.rawValue > 0)
{
attachImage.presence = "visible";
}
Hope that helps,
Niall