Convert HTML text into Readable text - Using Electronic Reporting in D365 Finance and Operations



Convert HTML text into Readable text - Using Electronic Reporting in D365 Finance and Operations

What's the Problem:

We are maintaining case logs for the different cases in the D365. The case log description can be written in Rich text format. This is the reason, case log descriptions are stored in the table as HTML text.

Have a look at the table browser

Text is saved as HTML text. If we try to create the reports and pick the data from this field, the system will pick the data as it is.

To test this, we can move into Electronic Reporting and do some debugging. For more info on Electronic reporting. You can visit Electronic reporting (ER) overview - Finance & Operations | Dynamics 365 | Microsoft Docs

In case you have missed my previous post, refer to Missing Number Sequence List - Electronic reporting.

Navigate to Workspaces -> Electronic Reporting -> Reporting configurations -> Create new configuration -> Add data model -> Map model to Data sources.

Add a Datasource of Table records "CaseLog" table. Click on start debugging

 



Now we are clear with our problem statement. Let's search for the solution.

 

Here is the solution:

 

I tried to search for some patterns in the Notes field. There are HTML tags like <div></div>, <span></span>, <br>, <p></p> etc along with the HTML attributes like style, margin etc. All the text which want to extract; comes after the character ">" but before the "</", so we need to remove all the other data which is lying between two tags.

I start searching over Google with the search words "how to remove the HTML characters from HTML text". Luckily I found some hints from the blog Convert Email Body from HTML format to Text | CloudFronts.

This blog is related to CRM but from the coding part, I got the idea of how to search for the text between two tags.

The main credit for the solution goes to the "Replace" function available in Electronic reporting. Refer to REPLACE ER Function| Microsoft Dynamics.

 

In the calculated fields, I write the formula as shown below:

REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(@.Notes, "[\n\r\t,]"" ", true)
        , "<( )*div([^>])*>""", true)
                , "<( )*span([^>])*>""", true)
                        , "<( )*br([^>])*>""", true), 
                                "<( )*p([^>])*>""", true), "<[^>]*>""", true) 

 

Let's check now from the debugger. Now data stored into notes are converted to normal text which can be used for reporting purposes.


Our problem is resolved. Thanks for reading.

 

Happy Neeraxing! 😃

By Neeraj Kumar

Comments

You might love these

Run ER reports using Electronic Messaging Functionality in D365

Bulk Posting of Journals in Dynamics 365 Finance and Operations

Calculate Preposted tax document on Purchases order confirmation in D365FO using Electronic reporting