This post includes a script which amalgamates the previous two posted triggers to enable email documents (purchase orders and check remittances) into one.
The below script creates a trigger on the SY04905 table to automatically flag the remittance and purchase orders to be emailed out in PDF format and using Message IDs of REMITTANCE and PURCHASEORDER respectively.
/*
Created by Ian Grieve of azurecurve|Ramblings of a Dynamics GP Consultant (http://www.azurecurve.co.uk)
This code is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0 Int).
*/CREATE TRIGGER utr_AZRCRV_Update_SY04905_Activate_All ON dbo.SY04905 AFTER Insert AS-- Enable Purchase OrderUPDATE
EmailSET
EmailDocumentEnabled = 1,EmailMessageID ='PURCHASEORDER',EmailDocumentFormat = 3FROM
SY04905 AS EmailINNER JOIN
insertedON Email.EmailDictionaryID = 0AND Email.EmailSeriesID = 4AND Email.MODULE1 = 12AND Email.EmailCardID = inserted.EmailCardIDAND Email.EmailDocumentID = 1-- Enable RemittanceUPDATE
EmailSET
EmailDocumentEnabled = 1,EmailMessageID ='REMITTANCE',EmailDocumentFormat = 3FROM
SY04905 AS EmailINNER JOIN
insertedON Email.EmailDictionaryID = 0AND Email.EmailSeriesID = 4AND Email.MODULE1 = 19AND Email.EmailCardID = inserted.EmailCardIDAND Email.EmailDocumentID = 6GO