Email Purchase order report when confirm through email

 Today we have requirment to send the purchase order report though email when confirm the purchase order :- 


In Microsoft Dynamics 365 for Finance and Operation, we usually get a requirement to email invoices from some dedicated From email address (e.g. invoicing@mycompany.com). Unfortunately, emailing reports using different From email addresses is not enabled in D365FO out of the box. Each outgoing email with a printed report is always sent from the email of the current user, for example tabsheer@mycompany.com.

Furthermore, if we select SMTP as the email provider (you can select Email provider in System administration > Setup > Email > Email parameters) we will also need to configure our mail server (for example Exchange Online) to allow the account specified in SMTP settings in Email parameters to send emails in the name of any user who emails reports.


Thus, when emailing reports in Dynamics 365 for Finance and Operations two problems can arise related to the sender email address:

  • We cannot specify From email address on outgoing emails (current user’s email address is always used).
  • Additional configuration of the outgoing mail server, e.g. Exchange Online is needed.

Go to System administration--->Setup--->Email--->Email parameters. Fill the required information to start the email alert

 

 


 

 

Step 2:- Go to the Organization administration--->Setup-->Organization email templates.. Create a new template with the preferred lang and put the place holder in between which can be placed against the value.

 

Please note the file upload only will be done in the HTML format. Which can show the result below once you upload  also attached example file with this.

 


 

 

Step 3 :- Go to Accounts payable-->Setup--->Forms--->Form setup and fill the details :-

 


Please note in the to email you can mention the admin email address we are handle the To email over the code with the parameter checks

 

 


 

Step 4 :- Now go Accounts payable--->Purchase orders--->All purchase orders create a new purchase order and Use the confirmation button .

 


Please note :- Use the print Po and print management setting to yes


 

 

 

 

 

Step 5 :- Once you click Ok you get a confirmation that email has been trigger

 

 


 Step 6 :- Codes to be written on the controller class of report

 

 [ExtensionOf(classStr(PurchPurchaseOrderController))]

final class PELPurchPurchaseOrderControllerCls_Extension 

{

    public SysEmailSubject messageSubject;

    public str messageBody;



    public void runReport()

    {

        str             email, emailRequester;

        str             xmlParameters;

        LanguageId      languageId;

        

        PurchTable      purchTable = purchTable::find(vendPurchOrderJour.PurchId);

        VendParameters  vendParameters = VendParameters::find();


        // To find the primary email for request as send in CC.

        if(purchTable.OrderAccount)

        {

            email = VendTable::find(purchTable.OrderAccount).email();

        }

        if(purchTable.Requester)

        {

            emailRequester = HcmWorker::find(purchTable.Requester).email();


           if(!email)

            {

                email = emailRequester;

            }

        }

        if(!email && !emailRequester)

        {

           

            email = xUserInfo::find(false,curUserId()).networkAlias;

           

        }


        if (reportContract.parmPrintSettings().printMediumType() == SRSPrintMediumType::Email)

        {

            Map mergeValues = this.getMergeValues(purchTable);


            xmlParameters   = this.createEmailParameterXml(mergeValues);


            languageId = purchTable.LanguageId;


            this.getEmailMessage(vendParameters.PELSysEmailTable, languageId, mergeValues, xmlParameters);


            reportContract.parmPrintSettings().parmEMailContract().parmSubject(messageSubject);

            reportContract.parmPrintSettings().parmEMailContract().parmTo(email);

            reportContract.parmPrintSettings().parmEMailContract().parmCc(emailRequester);

            reportContract.parmPrintSettings().parmEMailContract().parmBody(messageBody);

            reportContract.parmPrintSettings().fileName("Pelsis_" + vendPurchOrderJour.PurchId);

        }


        next runReport();


    }

==================================================================

    protected Map getMergeValues(PurchTable _purchTable)

    {

        // Create the key-value pairs for merge values of the email.

        Map mergeValues = new Map(Types::String, Types::String);


        mergeValues.insert('PoNo', _purchTable.PurchId);

        mergeValues.insert('PoNo', _purchTable.PurchId);

        mergeValues.insert('LegalEntityName', CompanyInfo::findDataArea(_purchTable.DataAreaId).Name);

        

        return mergeValues;

    }

==================================================================

    private void getEmailMessage(SysEmailId _emailId, LanguageId _language, Map _mappings = null, str _xmlData = '')

    {

        LanguageId              languageId;

        SysEmailTable           table = SysEmailTable::find(_emailId);

        SysEmailMessageTable    message;

        

        if (_language)

        {

            languageId = _language;

        }

        else

        {

            languageId = table.DefaultLanguage;

        }


        message = SysEmailMessageTable::find(_emailId, languageId);


        if (!message)

        {

            // Message not found for this language.

            message = SysEmailMessageTable::find(_emailId, table.DefaultLanguage);

        }


        if (message)

        {

            messageBody = this.getMessageBody( _emailId,

                                               _language,

                                               message,

                                               _xmlData);


            messageSubject = SysEmailMessage::stringExpand(message.Subject,_mappings);

            messageBody = SysEmailMessage::stringExpand(messageBody, SysEmailTable::htmlEncodeParameters(_mappings));

        }

        else

        {

            throw error(strfmt("@SYS74260", _language));

        }

    }


    protected  str getMessageBody( SysEmailId _emailId,

                                   LanguageId _language,

                                   SysEmailMessageTable message,

                                   str _xmlData)

    {

        boolean isHTML = (message.LayoutType == SysEmailLayoutType::DynamicLayout);


        if (isHTML)

        {

            messageBody = SysEmailBatch::doTransform(_xmlData, message.xsltMail);

        }

        else

        {

            messageBody = message.Mail;

        }


        return messageBody;

    }

==================================================================

    protected  str createEmailParameterXml(Map parameterMap)

    {

        MapEnumerator enum = parameterMap.getEnumerator();


        XmlElement alert;

        XmlElement node;

        XmlCDataSection value;

        XmlDocument doc = new XmlDocument();


        alert = doc.createNode(XmlNodeType::Element,'alert','');


        while (enum.moveNext())

        {

            node = doc.createNode(XmlNodeType::Element,enum.currentKey(),'');


            //closing tag for CDATA section is illegal

            if (!strfind(enum.currentValue(),']]>',1,strlen(enum.currentValue())))

            {

                value = doc.createCDataSection(enum.currentValue());

            }

            else

            {

                value = doc.createCDataSection('');

            }


            node.appendChild(value);

            alert.appendChild(node);

        }


        doc.appendChild(alert);


        //Axapta uses UTF-16 encoding

        return '<?xml version="1.0" encoding="utf-16"?>' + doc.xml();

    }


}

=============================================================== 

Comments

  1. The best ways to bet on college football, college
    The best ways to bet 김천 출장샵 on 대구광역 출장안마 college 과천 출장샵 football, college basketball, 경상북도 출장안마 Here are the most popular ways to bet on 김포 출장마사지 college football, college basketball,

    ReplyDelete

Post a Comment

Popular posts from this blog

Customization on Sales invoice Report in D365 F&O

75) COC - Create a coc of the table modified method

46) D365 FO: SHAREPOINT FILE UPLOAD USING X++