Thoughts, Dynamics 365, random business ideas, etc.

The Power Automate trick I wish I knew sooner – using alternate keys instead of GUIDs

I’ve been building Power Automate flows that take rows from Excel and create sales orders and sales order lines in Dataverse. It’s pretty standard, but I keep needing to reference related records (like the customer or a delivery warehouse or something) and I had to go get the GUID first. Here’s a blog post I wrote about how to do that.

Sometimes, in a more complicated example, that might mean a couple of Dataverse lookups per row. Taking the plain-text value from Excel, finding the GUID, and then popping that into the new row.

Seemed like there should be a better way.

Then I learned about alternate keys

I didn’t realize until today that you can reference records by their alternate keys when writing to Dataverse.

This means that instead of fetching the GUID first, you can write your record and directly reference another record using it’s natural key.

Microsoft has a doc about it , but I hadn’t come across it until today. Once you see how it works, it’ll change how you build a Power Automate flow.

Example – create a sales order and lines from Excel

Let’s say your Excel sheet looks like this:

SalesOrderNumberAccountNumberItemNumberQuantityCompany
SO-1001ACCT-123ITEM-0015USMF
SO-1001ACCT-123ITEM-0022USMF

For each row, I wanted to create a sales order line in Dataverse and associate it with the right account. Normally, I’d:

  1. Use List rows or Get row to find the account by account number
  2. Get the GUID
  3. Plug that GUID into the lookup field when creating the line

With alternate keys, I don’t have to do any of that.

The magic line

Here’s what this looks like instead:

accounts(_msdyn_company_value=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx,msdyn_siteid=’1′)

A couple of things you’ll see in the doc:

  1. For keys that use lookup fields, you’ll need the “_entity_value” syntax and need to use the GUID still. In my case, the company can be hard-coded, but if you have multiple companies, you might need to still find that one.
  2. The keys can be found in the Power Platform admin center by looking at the table and clicking the “Keys” button

Why this changes everything

Once you start using alternate keys this way, your Power Automate flows can become dramatically cleaner:

  • Fewer Dataverse calls (no pre-lookups)
  • Easier to read and maintain
  • Less chance of a failed lookup of GUID mismatch

I can’t believe I didn’t know this sooner.

Being able to use alternate keys when writing to Dataverse will completely change how I build my flows – especially in Dataverse environments connected to Finance & Operations where every record needs a company.

Next time you’re building a Power Automate flow that links to Dataverse entities, check your tables for alternate keys to save yourself a lot of headaches.


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Comments