Amey Holden

View Original

Insert your email signature from Dataverse using Power Automate

Creating and using signatures for Dynamics 365 and Dataverse (from here on in ‘Dataverse’) is nothing new. Automatically adding a signature into an email is driven by the user first setting up their default signature (see docs here), then physically creating or viewing a draft email record in the Dataverse UI (technical term: ‘client side’).

UPDATE: If your email signatures contain dynamic data tags such as inserting the phone number from the user record, ‘List Rows’ on email signatures approach will not work. Instead you can use an undocumented action called ‘InstantiateTemplateGeneric’ to retrieve and generate the signature but always take caution using undocumented actions as they are more prone to unannounced changes/deprecations. Thanks for the tip Tanguy!

Where’s my email signature?

I already have an existing flow that I call from a custom page (as seen here) which creates the dataverse email record and associated attachment. The result looks like this, the users signature is not automatically populated, which means it cannot be automatically sent and must be viewed/updated manually before sending.

Does the user have a default personal signature?

There is no guarantee that the user will have an email signature set up/assigned correctly. So we need to ensure we accommodate for both scenarios.

Add a ‘Condition’ action to check if out list rows action from above ‘ListRowsEmailSignatures’ returned any results

empty(body('ListRowsEmailSignatures')?['value'])

Use or create a signature

If the signature is found (therefore the list rows search is NOT empty) then we can set the signature to be the safehtml from the ListRowsEmailSignatures action, wrapped in the <div id="signature"> tags:

<div id="signature">
@{first(outputs('ListRowsEmailSignatures')?['body/value'])?['safehtml']}
</div>

If the signature is NOT found, then we can set the signature to be the fullname from the GetUser action, also wrapped in the <div id="signature"> tags:

<div id="signature">
<p>Kind Regards,
<br><br>
@{first(outputs('GetUser')?['body/value'])?['fullname']}</p>
</div>

What does <div id="signature"> mean?

As mentioned earlier, the signature population is triggered when the user physically creates or views a draft email record in the Dataverse UI. Before adding the signature it checks to see if one is already added, this is determined by a completed set of <div> tags with the id “signature”. If we do not add this as part of the automation flow, then when the record is next opened by a user who has a default signature set up - another signature will be added.

And they all lived happily automatedly ever after, the end.