Friday 30 November 2018

Job to combine main account and default dimension to get ledger Dimension in D365FO

In this blog I will discuss how we can combine main account and default dimension to get ledger dimension in D365FO. So let's begin, please follow below screen shots.

For achieving this I have created a Job in which I have three methods, which I have call in my main method.

Main() Method:

Source Code Explanation:
  • Set main account (in my case '61170005').
  • Set default dimension (in my case '68719489575').
  • Pass it into CombineMainAccoutAndDefaultDimension() method.
GetDimensionAttriuteName() Method:

Source Code Explanation:
  • Get dimension cache.
  • Iterate dimension attribute Set Item to get dimension attribute except main account.
  • Return dimension attributes container.


















GetDimensionAttributeValue() Method:


Source Code Explanation:
  • Find dimension attribute value set storage through default dimension.
  • Get display value by dimension attribute from dimension storage.










CombineMainAccoutAndDefaultDimension() Method:


Source Code Explanation:
  • Initialize and declare objects.
  • Get container which holds dimension attributes. (Get from previous getDimensionAttriuteName() method).
  • Iterate dimension attributes and get its values. (Get dimension values from previous getDimensionAttributeValue() method).
  • Pass attribute name and value in dimension attribute value contract.
  • Pass main account and value contract object in ledger account contract class.
  • Through dimension service provider get dimension storage.
  • Get dimension value combination of main account and default dimension.
  • Return value combination record id which is Ledger Dimension.
 

Result:









This example is taken from this Microsoft community post Combine main account with default dimension to ledger dimension

Job to get average unit cost of item through X++ code in D365

Recently I have encounter a scenario in which I want to get the average unit cost price of the item in D365FO. For that I have created a job to get the cost. Please follow below screenshots.

You can see the average unit cost price for item through this navigation Cost management -> Inventory accounting -> Released products -> Manage Costs (Tab) -> Costing (Section) -> Cost Object (Option).






















Source Code Explanation (1.1):
  • Initialize and declare objects.
  • Set Item Id = 'F-001' (in my case).
  • Get invent sum buffer through item id.
  • Check inventory dimension, in case of not found created one.

























Source Code Explanation (1.2):
  • Create an object of invent cost price cache class.
  • Get invent table buffer from invent sum.
  • Get from & to unit of measurement.
    • Construct secondary to invent unit converter buffer.
    • Get the convert value.
  • Get the OOTB cost price pieces method from cache class that will return average unit cost price of the item.










Result:



Thursday 29 November 2018

Email invoices using built-in email processing in D365FO

In my previous blog I explained how we can email invoices in Dynamics 365 for Finance and Operations with the nicely designed email body and additional email attachments such as Invoice specification or Term & Conditions. Everything worked just fine until we stumbled upon SMTP client timeout when we were emailing invoices in batch, and some emails failed to be sent. The reason was the limitations related to Online Exchange.

In order to resolve SMTP client timeout issue I have done some research on how this can be fixed, and I found the solution within the same free tool (Docentric) we used to email invoices with the nice body and additional attachments.

So, this problem can be solved with Docentric in two ways: 
  • Setting up (increasing) the SMTP client timeout.
  • Using email processing. This means that instead of sending an invoice right away after it is being generated, the invoice will instead be saved to Email sending status, the built-in outgoing email table used, e.g. for workflow email notifications.

SMTP Client Settings:

In Docentric free-edition tool global parameters we can set up SMTP client settings. Beside standard SMTP settings such as Outgoing email server, SMTP port, if SSL is turned on, etc. you can set up also SMTP client timeout, Body and subject encoding, Delivery format, etc.

Navigation: Organization administration -> Docentric AX -> Docentric AX parameters










Monitor & Save Outgoing Emails:

Out of the box in Microsoft Dynamics 365 Finance and Operations when we print an invoice to the Email print destination, it will be emailed synchronously, i.e. in process. This means that D365FO will wait for a response from the outgoing mail server, which can be Success or Failure. In case of Failure we will only get the error message without a possibility to resend the failed email.

Docentric free-edition tool offers the possibility to save outgoing emails with invoices to Email sending status. This is a standard table used for outgoing emails for workflows and retail notifications. The main advantage is that you can monitor the status of outgoing emails and define retry schedule.

Navigation: System administration -> Periodic tasks -> Email processing -> Email sending status

Now let’s demonstrate how to email invoices by using Docentric free-edition tool through Email sending status, i.e. outgoing email table. For this example I used Sales Invoice report which is emailed via Use print management from Invoice journal.

Navigation: Accounts receivable -> Inquiries and reports -> Invoices -> Invoice journal








Step: 1

Docentric report setup provides multiple options. There we can choose Email sending mode (Synchronous or Email processing) per report. If we choose Synchronous, it will run as out of the box, by sending the email with a generated invoice and additional attachments synchronously. On the other hand, if we choose Email processing, the email will be saved to Email sending status, i.e. the outgoing email table from where it will be sent later by Email distributor batch.

Navigation: Organization administration -> Docentric AX -> Reports

By navigating this link, it will open Docentric AX Reports. Click the Settings tab and select Email sending settings as shown on the image below.








When you click the
Email sending settings menu item, it will open a form in which we can select Email processing as Email sending mode. Please see the image below.










That is all you need to do in order to enable emailing your invoices using Email processing

Step: 2

For this example we have used the Sales invoice report, which can be printed using Print management setup, so we will now set up the print management settings.

Navigation: Accounts receivable -> Setup -> Forms -> Form setup -> General (Tab) -> Print management










Select
Customer invoice and click the marked button to change the target print destination.


























Provide To address, Subject and Body, and save your settings.



Step: 3

Now run your Sales invoice report using the Print management option. Please note that when we run the Sales invoice report out of the box without using Docentric Email print destination it will show below message in case of success.







But since we are using Docentric Email print destination with chosen Email processing as Email sending mode for this report, this time the email will be saved to Email sending status, i.e. the outgoing email table, and also the different message will be shown – please check the image below.








Now we can find the email in Email sending status in status Waiting. Here, in this form, you will be able to monitor and see the status of all outgoing emails.

Navigation: System administration -> Periodic tasks -> Email processing -> Email sending status



To send our email from Email sending status, we first have to make sure that we have SMTP server configured and running. Go to System administration -> Setup -> Email -> Email parameters and fill the required settings. Next step is to make sure that Email distributor batch is up and running. Go to System administration -> Inquiries -> Batch jobs and check if the batch job (E-mail distributor batch) exists with status Executing or Waiting. If it doesn’t, you can activate it from System administration -> Periodic -> Email processing -> Email distributor batch.

Now when we run Email distributor batch (as a batch job or without it) it will send all emails with the status Waiting, one by one (with retries and status controlling). The email status will change to Sent or Failed.

























Now refresh the Email sending status form. You can see in the image below that our email is successfully sent.






That is how Docentric free-edition tool helps us to save emails with generated invoices, send them reliably and monitor the progress of sending.

Email sending status enhancements:

Built-in Email sending status is also extended by Docentric free-edition tool.

  • Additional columns.
    • Context information (provides the information about the attached report)
    • Company Id (provides the information about the legal entity)

  • Download message as EML file that can be open with Outlook.

  • Show message is improved to show the list of email attachments as well. You can download one by simply clicking on it.


I found saving outgoing emails with invoices in Email sending status very useful, because we can now monitor and resend them if needed. But there is more what you can do with Docentric free-edition tool. In one of the next articles, I will show you how to email reports with different From email addresses.

Sunday 25 November 2018

Job to get the print management report format name through X++ code in D365

Recently I have a got a requirement in which I want to get the SSRS report format name selected in print management settings, for that I have created a job to get the report format name in print management settings.

For this example, I am using Customer Invoice report (e.g., SalesInvoice.Report).












Note: We can use print management settings for SSRS report through "Use Print Management" menu.

Source code explanation:
  • Document type here, Sales order invoice. (Enum)
  • Table joins:
    • PrintMgmtDocInstance table holds information about the overwritten destinations.
    • PrintMgmtReportFormat table contains SSRS report names that users can choose from as alternatives for reports that are controlled by print management.
    • PrintMgmtSettings table contains specific print management settings that are applied when a document is printed.
  • Get the report name from PrintMgmtReportFormat table, Name field contains the report format name.














Result:


Saturday 24 November 2018

Job to apply vendor prepayment on (PO) invoice through X++ code in D365

Prepayments are a common business practice, with organizations issuing prepayments to vendors for goods or services before those goods or services are fulfilled. To minimize risk, you can track prepayments by defining the prepayment on a purchase order. Vendors can also create a prepayment invoice that is associated with a purchase order.

In this blog, I will discuss how we can apply prepayment through X++ code.in Microsoft Dynamics 365 finance & operation.

Note: For applying the prepayment you need to have the vendor invoice, you can create manually or you can create it by X++ code Job to create vendor invoice (PO) through X++ code in D365.









For this example I have created a job, please see source code screenshots below.

Source code explanation (1.1): 
  • Initialize classes and tables buffers.
  • Get Vendor invoice by passing purchase order and invoice number.
  • Construct the VendAdvanceInvoice class.





















Source code explanation (1.2): 
  • Pass data to parm methods of VendAdvanceInvoice class.
  • Get purchase order amount calculation through PurchTotals class.
  • Iterate data of VendInvoiceInfoSubTable table.
  • Populate data in temporary tmpVendStandardInvoice table.












Source code explanation (1.3): 
  • Iterate record and populate data in tmpVendAdvanceInvoice table.













Source code explanation (1.4): 
  • Pass amount to applied as prepayment.
  • Pass temporary tables in OOTB of the vendAdvanceInvoice class.
  • Update invoice match status.











That is all you need to do, now build and run the job. 

Result:




Monday 12 November 2018

How to email invoices in the right way in Dynamics 365 for Finance and Operations

In my previous blog, I have mentioned that I got a requirement to email invoices with the nicely designed email body and subject containing customer related information such as Invoice ID and Customer account number. Besides, I needed to attach some additional documents to outgoing emails and sent them together with invoices. This is, I would say, such a common scenario for emailing invoices but unfortunately still not provided in D365FO OOTB.

So for achieving this requirement I have found a completely free tool called Docentric that provides far more options regarding all print destinations for all SSRS reports, not just Email print destination and Customer invoice. Read more about its features in my previous blog >>

In this article I will discuss how we can use Docentric free-edition tool to achieve the above described scenario:
  1. Send emails to customers with the professionally looking email body.
  2. Provide sender display name through Docentric AX parameters setup.
  3. Provide dynamic email subject, company logo and email body content using placeholders for Invoice ID, Customer name, Customer reference, etc.
  4. Create a new custom placeholder for Customer requisition.
  5. Add additional email attachment InvoiceSpecification_<InvoiceId>.pdf.
For this blog example, I have set up Docentric Email as the target print destination for the Customer invoice report in Print management setup for Accounts receivable: Accounts receivable -> Setup -> Forms -> Form setup -> General (Side menu) -> Print Management (link) -> Customer invoice -> Original <default>.



















You can easily test these settings when posting an invoice from a sales order or from Invoice journal as show on the image below.









Email an invoice:
Accounts receivable -> Inquiries and reports -> Invoices -> Invoice journal -> Invoice (Menu) -> Document (Submenu) -> View (Submenu option) -> Use print management.

Note: For emailing, you need to setup Email parameters: System administration -> Setup -> Email -> Email parameters.
There are two email providers: 1) SMTP 2) Exchange.













Please make sure your email settings are working otherwise you will not be able to send emails. From the 8.1 app version you can send a test email directly from this form. Now let’s back to the blog topic.

Requirement 1:

Send an email with the nicely designed body. Docentric free-edition tool provides both designer editor and html source code editor so you can design your emails easily. For this example I have got an email template as html file. You can find email templates over the Internet or create your own custom design.























View in design editor of Docentric free-edition tool.














View in source code editor of Docentric free-edition tool. Here you can see the HTML & CSS code.













Requirement 2:


Provide sender display name through Docentric AX parameters setup.

Sender display name can be provided in the Docentric AX parameters form: Workspace -> Docentric AX (menu) -> Related links -> Docentric AX parameters.















Under the
Emailing option, you can find the Email sender display name field and enter any text as you like (in my case “Docentric services”).


Requirement 3:

Provide dynamic email subject, company logo and email body content using placeholders.

3.1 Email subject can be provided at the highlighted section in below screenshot. By giving a placeholder, at runtime Docentric will resolve this placeholder with its value.


Note: You can make attachment name also dynamic, for example: Invoice_@InvoiceId@.pdf. In fact, you can use placeholders in any of print destination settings where this makes sense.

3.2 Company logo is the OOTB placeholder. You can find it in the Fields drop-down list. When you place company logo in the email body, it automatically resolves into image as shown below.



3.3 Placeholders for email body content. You can simple click a placeholder from the Fields drop-down list and the editor will create the placeholder in your email body.



Requirement 4:

Create a new custom placeholder for Customer requisition of corresponding sales order.

Docentric free-edition tool provides OOTB placeholders for Invoice and other reports. But you can also create your own custom placeholders by doing very minimal coding in one of Docentric model’s classes.

OOTB placeholders already appears in the Fields drop-down list as you can see in above screenshots. For our new custom placeholder Customer requisition we need to customize so called Docentric DSP (Data Source Provider) class for Customer invoice in the Docentric AX SSRS Replicas model: DocSalesInvoiceReportDSP. This model is not part of the product but it’s an optional model that serves as starting point for customization like this.

Note: For better understanding of Docentric DSP classes, you can read this documentation.

In next steps, I am going to add a new Customer requisition placeholder, which should contain value from the Customer requisition field of the corresponding sales order.


Source Code Explanation:
  • Declare the Customer requisition placeholder variable that will hold its value.
















  • Fill the placeholder value in the onSelectedRdpTableRecord() method:
      
       SalesTable salesTable = SalesTable::find(header.SalesId);
       placeholder_customerRequisition = SalesTable.PurchOrderFormNum;


Source Code Screenshot:

















  • Declare a macro.
#define.CustomerRequisition('CustomerRequisition')
  • In the overrideReportRunSettings() method add DocPlaceholderAttribute for Customer requisition.
DocPlaceholderAttribute(#CustomerRequisition, 'INV - Customer Requisition')
  •        Add the X++ code in overrideReportRunSetting() method, which replaces each occurrences of the @CustomerRequisition@ placeholder with its value.
// -- Placeholder @CustomerRequisition@
placeholderMng.replacePlaceholderInCurrentPrintDest(#CustomerRequisition, placeholder_customerRequisition);


Source Code Screenshot:
















Then build and sync your code. Please see the result in Docentric free-edition email editor on the screenshot below – our new custom placeholder is now shown in the Fields dropdown list.

Result:


















Requirement 5:

Add additional email attachment.

In Docentric free-edition tool you will be able to add additional email attachments using the same DSP class that handles placeholders. It’s up to you where to store documents that need to be picked and emailed as additional attachments of your outgoing emails. Common place is Attachments of the context execution table record, in our case Sales order.

Note: To add a document to Attachments to your relevant sales order record(s) follow bellow steps.

Step 1:









Step 2:


















For adding an attached document as additional email attachment using Docentric free-edition tool we need to write some code in the same overrideReportRunSetting() method as we did for the custom placeholder Customer requisition.

Source Code Explanation:
  • The addAdditionalAttachment() method adds an additional email attachment to the email that will be sent together with the report itself in case of Email print destination.
  • Method signature has two arguments.
    • Additional attachment name (e.g. 'InvoiceSpecifcation_InvoiceId.pdf').
    • Attachment file content.
  • For attachment name I am concatenating InvoiceSpecification with InvoiceId.
  • For attachment file content I am getting invoice specification document for the related sales order from the DocuRef table .This table contains the references between documents and their associated tables and records.
//Add additional document.           
_reportRunContext.emailPrintDestSettings().addAdditionalAttachment(
strFmt('InvoiceSpecification_%1.pdf', placeholder_invoiceId),                DocumentManagement::getAttachmentAsContainer(DocuRef::findTableIdRecId(curExt(), tableNum(SalesTable), SalesTable::find(placeholder_salesId).RecId)));

Source Code Screenshot:







Now build and sync the code and let see the final result of the email body, placeholders, sender display name and additional attachment.


Final Result:


Key Updates in Dynamics 365 F&O for Version 10.0.39

Here’s a concise summary of the  platform updates  in  Microsoft Dynamics 365 Finance & Operations version 10.0.39 (March 2024) : 1- Add...