Convert a DataTable to an HTML string using UiPath
A lot of times while sending mails we need to include tables in the body of an email while automating a business process.
For this reason we need to convert the whole datatable to html string.
So that will be inserted in the body of an mail.
The old process is to iterate it through each row and appending every row value and creating an HTML string.
But for that UiPath made a new update to the mail activities package.
If you haven’t upgraded your mail activities to the version shown below do it now:
Let’s get into the practical implementation using UiPath.
Step1: Drag and Drop a Build DataTable Activity and create a datatable as shown below:
Now we have the datatable let’s see the new activity from the update.
Step2: Drag and Drop the Create HTML Content from the activities panel to the designer panel as shown below:
Now let’s see how we can insert a datatable into it.
Step3: Click on Open Editor then you will be able to see a screen like below:
Step4: Click on Add data Values at the top right corner then you will see a screen like below:
Step5: Now click on Map data value and you will see a screen like below:
When you click on Add Value you can see the table option there which will help us to add the table to this editor.
Step6: After clicking on the table in the same window we can add the datatable as shown below:
After adding this you will see that table is added to Add data values section in the editor that looks like below:
Step7: Now click on the table that is showing in Add data values section and then that is added to the editor as shown above.
This is it for setting up for adding a datatable in this editor.
Let’s see the output html string from this activity.
Step8: Create a variable that can hold this value in this example it is DttoHtmlString and the variable type is a string.
The output looks like below:
This is how we convert a DataTable to an html string in UiPath.