Stored Procedures [dbo].[AttachDocumentsToOutgoingEmail]
Properties
PropertyValue
ANSI Nulls OnYes
Quoted Identifier OnYes
Parameters
NameData TypeMax Length (Bytes)
@inOutgoingEmailIdint4
@inMssDocumentsPriKeyToIntMapmax
@inInvoicedHeadersPriKeyToIntMapmax
Permissions
TypeActionOwning Principal
GrantExecuteMssExec
SQL Script
CREATE PROCEDURE [dbo].[AttachDocumentsToOutgoingEmail]
    @inOutgoingEmailId int,
    @inMssDocuments PriKeyToIntMap readonly, /*Prikeys are the mss document IDs.  second value is the attachment order*/
    @inInvoicedHeaders PriKeyToIntMap readonly
AS
begin
    set nocount on
    insert into OutgoingEmailDocumentAttachment(
        OutgoingEmailFID,
        MssDocumentFID,
        AttachmentOrder
    )
    select @inOutgoingEmailId,
        MssDocumentFID = Documents.Id,
        AttachmentOrder = min(Documents.[Value]) -- prevent trying to attach the same document multiple times
    from @inMssDocuments Documents
    group by Documents.Id

    insert into OutgoingEmailInvoiceAttachment(
        OutgoingEmailFID,
        InvoicedHeaderFID,
        AttachmentOrder
    )
    select @inOutgoingEmailId,
        InvoicedHeaderFID = InvoicedHeaders.Id,
        AttachmentOrder = min(InvoicedHeaders.[Value])
    from @inInvoicedHeaders InvoicedHeaders
    group by InvoicedHeaders.Id

end
GO
GRANT EXECUTE ON  [dbo].[AttachDocumentsToOutgoingEmail] TO [MssExec]
GO
Uses