Friday, 25 February 2022

Microsoft Powerflow - Dynamics 365 - Get Email Template by Title

Let’s assume that you create a Cloud Flow that you will interact with for example trough a button in the account form ribbon.

When i started to work with Flows was already a couple of years ago, before i was using the Premium artifact for Dynamics 365, now we use the Dataverse artifact to interact with Dynamics 365.

For developers used to Web Api, and Odata, the queries that are needed in the Power Flow are kind of similar with the query string for interacting with CRM.

The example i want to show in this post is how to get an Email Template by Name with Dataverse in the flow. 

Please see below image regarding this example:

In my case my Email Template title is ‘[Account] - Send Gift to Customers’, to do that, we just set the Filter rows text as (title eq ‘[Account] - Send Gift to Customers’).

Assuming that you require only a couple of fields to be returned you can add them separeted by (,) in the ‘Select columns’ field.

Assuming that you need to use the ‘Email Template Id’ field returned by the call, there are a couple of ways of doing, for instance, you can add the artifact ‘Parse JSON’ where you add the body of the return and for the payload, you can copy and paste from the result of this item and collate after clicking on “Generate from Sample”.

Actually when working with Logic Apps and Power Flow you start to understand how things work and get used with small tricks to avoid adding unnecessary artifacts when you need only one or two properties.

In here, because i needed only the Email Template Id returned, and i knew it would be only returned 1 row, whenever you need to use it do the following:

  1. Start to select the ‘Expression’ and write first()

  2. Position the cursor inside of the brackets, and click on ‘Dynamic COntent’

  3. From the right artifact, select the property needed, in my case ‘Email Template Id’ and click ‘Update’

The result if you use the ‘Peek Code’ by clicking on the 3 dots from the artifact (in my case, the one on the screenshot above) will be something like:

first(outputs(‘Get_Email_Template_where_title_=’‘[Account]-_Account_send_gift_to_customers’’’)?[‘body/value’])?[‘templateid’]

So, i didn’t need to use the artifact for Parse the Json result returned from the call to after use the property templateid.

Hope it helps.

Wednesday, 9 February 2022

Microsoft Powerflow - Filter Json Array

 Recently I had to filter a Json Array of objects in Powerflow.

Let’s say we have a list of accounts and we need to filter by city name. In My case I was getting the data trough Dataverse.

In order to achieve this on another array of Cities only, we can use the approach present in the below image.

Explaining the image we have the following:

  1. Value, in my case is the list of Cities that i have extracted from CRM from a custom entity.

  2. @equals(item()?['dm_city'], first(outputs('Get_Cities')?['body/value'])?['dm_cityname'])
    Where item()?[‘dm_city’] represents the field from the custom City entity The second part of the condition is ‘first(outputs(‘Get_Cities’)?[‘body/value’])?[‘dm_cityname’])’ where ‘dm_cityname’ represents the field from the dataverse query where the accounts were returned.

Hope it helps.

Saturday, 5 February 2022

Microsoft Powerflow - Dynamics 365 - Adding email attachments


 Consider this situation: you are working with Microsoft Dynamics 365 and need to generate an email using an email template, including attaching the email attachments.

It was a little bit tricky to figure out how to do it, the reason of that being the UI itslef induces the developer in error.

See the image below where we will explain what to fill and how to fill the data.

Explaining the fields to fill:

  1. Attachment(Attachments), this is the first trick field, the UI tells you that is a required field, than makes you thinking that you need to set a GUID if you read the content of the text box without any data. However, after trying and trying, i set the value to a null trough the Expression set data type, don´t try as Dynamic.

  2. Entity, this is without any doubts the most weird one, when you try to fill, it only allows to options, ‘Email Template’ and ‘Email Activity’. In this case, we thought we needed the Email Activity because we were creating a Email Attachment to an Email. The error given by the history is the one below:
    The entity with a name = ‘4200’ with namemapping = ‘Logical’ was not found in the MetadataCache….
    After googling and trying, i found the solution to be set the field as email as per printscreen. Has to be set as selecting ‘Enter custom value’, and set as email.

  3. The other fields are more or less explanatory, as per screenshot.

Hope it helps.

CRM 365 Cloud - Disassociate 2 records using typescript

In case you need to Disassociate 2 records, please find below the code that allows you to do that.      export async function DissociateE...