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!

Meet the users

There are two types of users in this world - the ones who set up their email signature in Dataverse, and those who don’t.

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.

Who triggered the flow?

We start from someone pressing a button on a custom page, we need to find out who this is in term of their Dataverse user record ID so we can use that to get hold of their email signature and also send the email ‘From’ this user too.

There is an ‘x-ms-user-id’ that gets returned in the power app button trigger, however this is the users Azure ID, not their Dataverse User ID.

Find the user via 'x-ms-user-email'‘

Add a ‘List Rows’ Dataverse action and configure as below -

Action name: GetUser
Table name
: Users
Select columns: systemuserid,fullname
Filter rows: internalemailaddress eq '@{triggerOutputs()['headers']['x-ms-user-email']}' and isdisabled eq false

Find the users default email signature

Add another ‘List Rows’ Dataverse action and configure as below, we can use the user ID from the action above, to filter the email signature records to find the users personal default one -

Action name: ListRowsEmailSignatures
Table name
: Email Signatures
Select columns: safehtml
Filter rows: _owninguser_value eq '@{first(outputs('GetUser')?['body/value'])?['systemuserid']}' and isdefault eq true and ispersonal eq true

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.

Create and populate the email

We can be sure that either way the EmailSignature variable will now be populated with an appropriate signature for the user who pressed the button. I use some dynamic content from other part of the flow/custom page but the important things to do here are

  • Add an activity party ‘From’ and set using the system user ID we found earlier systemusers(@{first(outputs('GetUser')?['body/value'])?['systemuserid']})

  • Insert the email signature at the end of the email body (aka Description) @{variables('EmailSignature')}

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

Previous
Previous

Create sales tasks and phone calls directly from Real-time Dynamics 365 Marketing Journeys

Next
Next

Document generation before your eyes and on demand with Power Automate