Power Automate | Get & Set Combination Address

Microsoft is encouraging the replacement of traditional workflow processes with Power Automate (formerly Microsoft Flow). And with that change, there are certain times where flows handle items differently, and we, as developers, need to find the best methods to develop solutions that contain flows.

This blog will demonstrate how to set a single combination address field from a set of OOB (out of the box) and custom address fields.

Situation

There are times when a single combination, or composite, address is needed throughout the system. It could be used for mailing purposes or display purposes in D365 (Dynamics 365), SSRS reports, or flows.

Microsoft provides an OOB composite address field.

The problem is that all address fields that make up this field are Single Lines of Text. Often, there are custom lookup or Option Set fields that need to be a part of this composite address. Instead of users typing in Province, the organization would prefer them to select from a list to avoid spelling errors or abbreviations. Using lookups in cases like this dramatically improve charts, dashboards, filtering views, and reporting.

The current OOB composite address field is missing my custom Province, Region, and Country lookup values.

One partial solution would be to sync the OOB Address 1: State/Province Single Line of Text with the custom Province lookup. Every time the custom Province lookup field is modified, some custom automation would sync the Address 1: State/Province, thus keeping the OOB composite address intact. This would not interfere with Bing Maps, geocoding, and other elements that depend on the Single Line of Text state/province, country. But what if we have other fields like Region, Location, or Territory that should make up the composite field that are not represented with the OOB fields in the composite address?

What can we do to fix this?

Solution

We need to create a series of flows that will retrieve lookup name values, set the composite address value, and update the appropriate field and record. Let’s get started.

Flows Needed

Common Data Service (Current Environment) When a record is created, updated, or deleted (1 each):

  1. Set Business Office Address

When an HTTP request is received (4 each):

  1. Get Combination Address
  2. Get Province Name
  3. Get Region Name
  4. Get Country Name

Actions Needed

  • Initialize variable
  • Set variable
  • Condition
  • Get record
  • Run a child flow
  • Append to a string variable
  • Respond to a Power App or flow

Expressions Needed

  • length
  • null
  • concat

First, we need to create the custom composite Single Line of Text field on the desired entity. If you have multiple addresses for the entity, you will need to create a custom composite field for each. Again, to reemphasize, this is not to replace the OOB composite field which is used with items like Bing Maps and geocoding; it is for those situations where you need a specific display of a composite address.

It is a good idea to create all the child flows before embarking on the parent flow, so let us go ahead and do that. Because Province, Region, and Country are lookup fields, we need a child flow to retrieve the name value of the record rather than the GUID value. I will use the Get Country Name child flow as the example for all three.

Get Country Name (Child Flow)

Overview

This flow will receive a D365 record GUID and return the display name of the record so it can be used in the main address flow; otherwise it would enter the GUID value which isn’t very helpful.

While inside Power Platform and from within an existing solution, select New and then Flow.

Enter the search box, and type “Request.” You will find “When a HTTP request is received.” Select it.

Power Automate

Click the sample payload link and enter the following JSON. You can change “Country” to your desired field name.

{

“Country”: “17bcaf10-35ff-e911-a811-000d3af3a0d7”

}

Click New step and search for Initialize variable.

Power Automate

Give your variable a name and set the type to String. Leave the Value empty.

Click New step and search for Get Record.

Select “Current” for Environment, select appropriate entity, and then set the Item identifier to the incoming parameter name; in this case, it is Country.

Click New step and search for Condition.

Power Automate

Use the length expression and then select the Name, or desired field, from the Get Country action. Change the equation to is greater than and then enter 0 as seen above.

length(outputs(‘Get_Country’)?[‘body/ebs_name’])

In the yes condition, click Add an action and search for Set variable.

Power Automate

Choose the correct variable and set the Value to the Name, or desired field, value from the Get Country action.

In the no condition, click Add an action and search for Set variable. Choose the correct variable and set to the null expression.

Power Automate

Finally, underneath and separate from the condition, click New step and search for Respond.

Power Automate

Give the outgoing parameter a name and set the value to the Country Name variable value.

This flow is complete. Ensure you save the flow and publish all customizations back in Power Platform.

If you have other lookup fields that need to be a part of the composite address, follow these steps as necessary.

Get Combination Address (Child Flow)

Overview

Power Automate

Now, we are ready to create the main child flow, the flow that will combine all fields to be used to set the composite address field.

While inside Power Platform and from within an existing solution, select New and then Flow.

Power Automate

Enter the search box, and type “Request.” You will find “When a HTTP request is received.” Select it.

Power Automate

Click the sample payload link and enter the following JSON. You can change the fields as needed to your desired field names.

{

“Street1”: “999 east main street”,

“Street2”: “Block 55”,

“Street3”: “Apt 22”,

“City”: “Vancouver”,

“Province”: “British Columbia”,

“PostalCode”: “V1X 6S4”,

“Region”:”Okanagan”,

“Country”:”Canada”

}

Click New step and search for Initialize variable.

Power Automate

Give your variable a name and set the type to String. Leave the Value empty.

Click New step and search for Condition.

Power Automate

Add the condition where field “is not equal to” with the null expression. In the yes condition, click Add an action and search for Set variable. Select the correct variable in the Name field and then populate the Value field with the incoming field (Street1 in this case).

Under the Combination Address variable, click the plus sign and select Add Parallel Branch.

Power Automate

We need to make sure the incoming parameter has a value, so we need a condition to check for its existence. In the new branch, search for Condition.

Power Automate

Select the desired incoming parameter field (Province) and set the next field to “is not equal to” with the null expression.

In the yes condition, click Add an action and search for Append to string variable. Select the correct variable in the Name field and then populate the Value field with the incoming field (Province in this case), using the concat expression.

concat(‘, ‘,triggerBody()?[‘Province’])

This is a cool action where we can add to an existing variable. The Street 1 was the first branch, so we didn’t need it.

Once all the branches are developed, click New step underneath the branches and search for Respond to a PowerApp or flow.

Give the returning parameter a name and set to the CombinationAddress variable.

This flow is complete. Ensure you save the flow and publish all customizations back in Power Platform.

Set Business Office Address Flow

Overview

Power Automate

It is time to create our final main parent flow. A flow will need to be created for each address. For example, in the D365 environment in which I’m working, there are three addresses: Home, Office, and Mailing. If I needed this functionality for all three addresses, I would need to create three main parent flows. Here, I’ll create a parent flow for just the Office address.

While inside Power Platform and from within an existing solution, select New and then Flow.

Power Automate

Enter the search box, and type “when a record is.” Ensure you have the Common Data Service (Current environment) When a record is created, updated, or deleted trigger. If you don’t see it right away, you may need to click the down arrow underneath the x and find it below. Find the appropriate trigger and select it.

Search for “when a record is” and click down arrow.

Power Automate

Select Common Data Service (current environment).

Power Automate

Select When a record is created, updated, or deleted.

Power Automate

Select the desired Trigger condition, select the appropriate entity, and set the desired Scope. Enter the field logical name of each field that should trigger this flow into the Filtering attributes. Enter them and separate them with commas but no spaces.

Power Automate

To find the field logical name, navigate to solutions, search for the field, and notice the Name column.

Power Automate

Click New step and search for Initialize variable.

Power Automate

Enter Name, set Type to String and leave Value blank. This variable will hold the entire address.

Now, we need to create a variable for each lookup field we need to pass onto our Get Combination Address child flow: Province, Region, and Country. To understand how to create child flows to retrieve the display name from a lookup, read Get Country Name section above.

Since I know I want three of these types of actions, I will use flow parallel branching. In order to utilize this nice feature, we need to go ahead and initialize the first variable.

Under the Office Address action, click New step and search for Initialize variable.

Power Automate

Enter Name, set Type to String and leave Value blank. This variable will hold the Province value.

Click Add an action and search for condition.

Power Automate

Select the desired field (Office: Province), set comparison to “is not equal to” and enter the null expression.

In the yes condition, click Add an action and search for Run a child flow. Select the correct child flow (Get Province Name) and enter the correct D365 field (Office: Province).

Click Add an action and search for Set variable. Select the correct variable (Province) and select the previous child flow response (ProvinceName).

In the no condition, click Add an action and search for Set variable. Select the correct variable (Province) and enter the null expression for Value.

This was the first branch. Right under Office Address initialize variable action, select the plus sign and then select Add a parallel branch.

Power Automate

 

The work above is pushed to the left in its own branch and a second branch is created.

Power Automate

Repeat all Province steps for each lookup value that needs to be passed to the main child flow, and you will end up with something like this.

Power Automate

Under all the branching, click New step and search for Run a child flow. Select the main child flow (Get Combination Address). This step is sending all the parameters to the main child flow.

Power Automate

For all Single Line of Texts, select the right D365 field from dynamic content. For all lookup values, select the corresponding variable. This child flow will take all values and return the Single Line of Text composite address value.

Click New step and search for Update a record and select the Common Data Service (current environment) action.

Power Automate

Select the correct entity, select the unique identifier from the trigger when a record is created, updated, or deleted from dynamic content, and then select the main child flow response (CombinationAddress).

To test, ensure you have saved all flows and published all customizations. Then go to the desired record, ensuring you have refreshed (F5) and change one of the address fields you entered into Filtering attributes from the trigger.

If everything worked correctly, you would have a composite address like the below in which you can use throughout the D365 environment, emails, SSRS reports, etc.

Power Automate

If you’d like to learn more about using Power Automate, please connect with us.

18 Warning Signs You Need The Cloud

If your business experiences these red flags, your diagnosis is clear: time to adopt the cloud!

Get The Report

18 Warning Signs You Need The Cloud

Get The Report