Tuesday 9 April 2019

Job to get contact person name and contact number of purchase order delivery address

In this blog, I will discuss how we can get the contact person name and contact number of purchase order delivery address located in the line details tab of PurchTable form.

Source Code:









public static void main(Args _args)
    {
        LogisticsElectronicAddress  electronicAddress;
        PurchTable                  purchTable;
        LogisticsLocation           logisticsLocation, logisticsLocationParent;

        purchTable = PurchTable::find("PurchaseOrderId");
        logisticsLocationParent = LogisticsLocation::find(purchTable.deliveryAddress().Location);

        select ParentLocation, RecId from logisticsLocation where
                logisticsLocation.ParentLocation == logisticsLocationParent.RecId;

        electronicAddress = LogisticsElectronicAddress::findByLocationAndType(logisticsLocation.RecId, LogisticsElectronicAddressMethodType::Phone);

        info(strFmt("Contact number: %1", electronicAddress.Locator));
        info(strFmt("Contact Person : %1", electronicAddress.Description));
    }

Monday 1 April 2019

Automatically redirect printing of invoices from Email to Printer if customer contact email address is missing

We usually want to deliver invoices to our customers via email. However, if a customer doesn’t have a contact with the email address in D365FO, emailing of the invoice will fail. It would make sense to have such invoices printed to a printer instead so that we can send them by postal mail. Using a free add-on for D365FO called Docentric, this can be automated with just a few clicks. In this article, I will show you how we can set up and use this functionality with Docentric.

In order to email an invoice to a customer primary email contact, we need to use the @@ email token. We can also use any other purpose token, for example  @Invoice@.














So, when such a token cannot be resolved since a customer doesn’t have any contacts with email addresses, emailing of an invoice for such customer will fail. Instead of failing, Docentric will enable us to redirect execution of this report to a new preconfigured print destination, for example to a particular printer.


Let’s say a customer has the primary contacts.  So, each time when an invoice is emailed to the primary contact (@@ Email token in Email To field) using Print management, the emails with the attached invoice document will be sent to the corresponding customer contacts as shown in the images below.






Now, what if a customer has no primary contact? As you can see in the image below, resolving this email token results in warning, and no email will be sent.



This built-in behavior can be changed if you are using Docentric AX Free Edition so in case the customer contact email address is missing we automatically redirect printing of invoices from Email to Printer. Please follow step by step process to configure an alternative print destination.


Step: 1
For printing customer invoice report we need to register SalesInvoice.Report in Docentric report setup (Organization administration -> Docentric AX -> Reports) to use Docentric AX functionalities.

Note: For detailed understanding and how to register reports in Docentric report setup you can refer this How to Set Up Reports article.












Step: 2

In Docentric report setup click the Settings > Email sending settings button, which opens the Email sending settings form, where you can see the Email tokens tab. This fast tab offers the possibility to specify how to deal with unresolved Email tokens in Email To, Cc and Bcc fields if the Docentric Email print destination is used for printing a report.












The Email tokens fast tab contains a grid where you can specify per-company the following:

  • What should happen if tokens in Email To field were not resolved (Redirect To & Redirect If fields in the image below)? You can specify various options for redirecting. (In our case I am going to redirect email to the printer if tokens are not resolved)
  • Should the warning messages be displayed (Show warning message field below) if Email tokens in Email To, Cc and Bcc fields were not resolved?

In this Email token feature of Docentric following settings are available:
  • Company Id: If no record for the current legal entity exists, you will get the standard D365FO behavior.
  • Redirect to button: opens the Print destination settings form for the selected record, where you can modify the Redirect to print destination.
  • Redirect if: specifies the condition under which the print destination redirection should happen. You have the following possibilities:
    • Never: if you don’t want to redirect your report but you still want to be informed about the unresolved tokens you can use this option.
    • To field is empty due to unresolved tokens: this is the most important option which prevents the situation where the report is not sent, and you even don’t know about it.
    • Primary contact token is unresolved: redirect if the primary contact token (@@) is used in the Email To field and is not resolved.
    • No Purpose token is resolved: redirect if Purpose tokens (such as @Invoice@, @Business@ or similar) are used in the Email To field and none of them is resolved.
    • No token is resolved: combination of the above two settings. This option is useful if you want to have control of your data quality.
    • At least one token is unresolved: similar as above, your Email might be sent but miss an important recipient, so this option helps improve your data quality.
  • Show redirection message: if checked, the information about the redirection will be printed.
  • Show warning message: if checked, the Warning about the redirection will be printed.
That is all you need to setup the email which automatically redirects printing of invoices from Email to printer if customer contact email address is missing. After running the customer invoice report in the below image you can see the result which is redirecting the email to printer in case of email tokens failure.









Email token feature is very useful in cases when you are printing hundreds of Invoices to the Email print destination. Without it, in case of the unresolved tokens you would only get the message
"Error while executing report", without any other information about the Invoice document being printed or the Customer missing the contact information. You will have a really hard time identifying the unsent invoices. Even if the Email To field isn’t empty and the report is emailed, but some of the tokens were unresolved, you would want to be able to identify such parties missing the necessary contact information, so that you can improve your data quality and to know that the email didn’t reach some important destination.

For further email token settings and detailed understanding, you can refer to Email Token (Docentric) article.

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...