Populate Multiple Fields from Reference Attribute

If you have questions or if you want to share your opinion about Aware IM post your message on this forum
Post Reply
bkonia
Posts: 98
Joined: Fri Jan 19, 2007 4:41 am
Contact:

Populate Multiple Fields from Reference Attribute

Post by bkonia »

I'm trying to create a system that will allow me to add multiple attachments to an email using a reference attribute, rather than using a separate attribute for each attachment. The benefit is that I can then have a BO containing a library of documents that I can attach to any email.

I've added the reference attribute to my email BO and I'm able to add documents to the email. However, my understanding is that the OutboundEmail notification must contain a single attribute for each attachment: Attachment1, Attachment2, Attachment3, etc... Therefore, I need to be able to populate these attributes in the OutboundEmail notification from the reference attribute in the email BO.

In other words, the rule would look something like:

CREATE OutboundEmail WITH OutboundEmail.Attachment1 = OutgoingEmail.Attachments[1], OutboundEmail.Attachment2 = OutgoingEmail.Attachments[2], OutgoingEmail.Attachment3 = OutgoingEmail.Attachments[3]

How can this be accomplished? Is there a way to reference individual elements within a Reference Attribute result set?
Brad S Konia
Hostland
https://www.hostland.com
aware_support2
Posts: 595
Joined: Sun Apr 24, 2005 2:22 am
Contact:

Post by aware_support2 »

Here is how you can do it. Object OutgoingEmail should have multiple-allowed attribute Attachments of type Attachment. Object Attachment has attributes Doc of type Document and calculated attribute OrderNumber of type number. Attribute Doc would hold a file. Attribute OrderNumber can be set with a rule like this:

Attachment.OrderNumber = COUNT Attachment WHERE (Attachment.ID <= ThisAttachment.ID AND Attachment.Email = ThisAttachment.Email) + 1

You could then add rules to notification OutboundEmail to initialize each of its Attachment attributes, for example:

FIND Attachment WHERE Attachment IN OutboundEmail.OutgoingEmail.Attachments AND Attachment.OrderNumber = 1
OutboundEmail.Attachment1 = Attachment.Doc

FIND Attachment WHERE Attachment IN OutboundEmail.OutgoingEmail.Attachments AND Attachment.OrderNumber = 2
OutboundEmail.Attachment2 = Attachment.Doc

...

Each initialization rule should be entered as a separate rule to OutboundEmail.

You would also need to add the following rule to object OutgoingEmail to ensure there are no gaps in attachment numbers when an attachment is removed from the list:

If Attachment WAS REMOVED FROM OutgoingEmail.Attachments Then
FIND Attachment WHERE Attachment IN OutgoingEmail.Attachments
UPDATE Attachment
Aware IM Support Team
bkonia
Posts: 98
Joined: Fri Jan 19, 2007 4:41 am
Contact:

Post by bkonia »

Thanks! I will definitely give that a try.

It would be really cool if the OutboundEmail and IncomingEmail notifications directly supported reference attributes to attachments. In other words, you would just add a reference to the Attachment BO in the notification attributes and Aware IM would automatically process an unlimited number of incoming and outgoing attachments.
Brad S Konia
Hostland
https://www.hostland.com
bkonia
Posts: 98
Joined: Fri Jan 19, 2007 4:41 am
Contact:

Post by bkonia »

I thought about this some more and I came to the conclusion that this solution does not address my primary objective. I want to be able to create a library of documents that can be attached to any email, by reference. The idea is to save database space by eliminating redundant storage of frequently used documents, and also to be able to select documents from a list within the application, rather than having to manually upload the document from the file system each time you want to send it.

The problem with the solution you proposed is that the OrderNumber attribute would only store the OrderNumber for one email. But what happens if you want to attach that same document to another email? The other email may have a different set of attachments from the first email, so you could easily end up with conflicting OrderNumbers. Your solution moves the storage location of the attachments from the email itself to a separate attachments BO, but it does not allow for attaching the same document to more than one email.

I suppose one way to accomplish this would be to create a separate AttachmentOrderNumber BO and maintain a separate set of AttachmentOrderNumbers for each email, but this is really adding a lot of complexity to the application. Any thoughts on my idea to allow for attachment reference attributes in the notifications?
Brad S Konia
Hostland
https://www.hostland.com
Post Reply