Microsoft Power Fx + XRM Tokens

Why mixing two very different but very similar features?
I hope you will see it, if you read on…

What’s a Token?

I don’t really know why… but it’s a word, a special word, representing other words… where the word is a data word, will be replaced with words from the actual data, as it is actually used. I think.

Ok, I started this post in the wrong way, since I can hardly explain it. I’ll restart the post, without explaining “token”.


XRM Tokens?

The XRM Tokens is just the name of this feature. Just accept it, just use it, just live with it. I do it now.

I started to create this feature 10 or 12 years ago, before Dynamics CRM Word Templates, before mscrm-addons, before Microsoft Automate, before Dynamics 365 Custom Actions… well ok, maybe I’m a bit wrong about back in the days, but since there was no feature as good as we needed, I started to work on it anyway.

We like to create solutions that are dynamic, to stay agile – so we don’t need to update the “code” in our Dynamics CRM solutions. We wanted to be able to deliver solutions that can be altered by the customers’ super users. Without making changes in the “code”.

Be agile.
Be dynamic.
Deliver dynamic solutions.
Deliver more.
Just use Dynamics 365.


Historical typical use case

Before good enough Word templates and email templates, we should be able to create nice emails and documents. Like this:

Hi Jonas,

Thanks for ordering our products:

Product..Flavor..Count....'a...Price
Pen......Black...3pcs...$2,00..$6,00
Rubber...........2pcs...$0,40..$0,80

Order number: ABC123
BR Lisa

That is (at least it was) really hard to fix, and easily possible to change in the text also.

So I created the XRM Tokens feature. Well not called like that from the beginning.

So the general email was written like this:

Hi {customerid.firstname},

Thanks for ordering our products:

Product..Flavor..Count....'a...Price
<expand|orderitem|orderid|{productid.name|<Pad|R|20>} {productid.flavor|<Pad|R|10>} {count}pcs {productid.price} {productid.price|<Math|*|count>}|itemno|\n>

Order number: {ordernumber}
BR {ownerid.firstname}

This email should be run from an Order. The Order has an M:1 relationship with the Customer (contact in this case), an M:1 relationship with the Owner (systemuser), and a 1:M relationship to OrderItem. OrderItem has an M:1 relationship to Product.

The easiest is the show the order number, just an “attribute”. Read in the docs!

Next one is almost as easy, getting the relationships attribute to the names of the customer and the seller. Same docs! These are probably possible in any templates from Microsoft.


Improvements

We really needed a possibility to show all “children”, from the 1:M relationships. So I created the Expand feature… I urge you to read these docs!

This tool, or rather this feature, a part of my open-sourced code, has grown over the years…

We added iif – why “iif” instead of “if“? It came from SQL Server language for a “one line if clause“. We added more and more… System, Format, Sequences, Random, RecordURL… (get to docs by clicking them!)


Use XRM Tokens

These features could be run from plugin, from javascript, from workflow, from Custom API, even from console apps.

It is now enable to deliver dynamic solutions, better than requiring code-changes

Today it is mainly used from the Bulk Data Updater in XrmToolBox. Updating attributes in “many” records at once, with dynamic data, calculated with XRM Tokens. But also for plugins etc…


Level Up Up Up! ↗

The First Level of the dynamic solutions we deliver, is to use Templates. For emails, for Word files, and so on.

The Second Level is to use the XRM Tokens. You can simply do more. Of course, we want to be able to do more, no?

The Third Level is starting to get a bit crazy… Not just Templates, not just XRM Tokens – but now mixing XRM Tokens together with Microsoft Power Fx.
I get dizzy now… 😵

To me, it’s like
meta square meta square meta.
Or is it called meta cube?


Use XRM Tokens + Power Fx = 😍

Go read the docs first. You can see a few examples there.

You enter the Power Fx formulas, between the | and the >

<PowerFx| formula >

Within the Power Fx formulas, you can get dynamic data, using the “normal” XRM Tokens formulas:

<PowerFx|Proper("{fullname}")>

What is actually sent to Power Fx to evaluate it would be:

Proper("jonas RAPP")

And the result would be:

Jonas Rapp

The Tools 🛠

The tool XRM Tokens Runner can help you create these formulas a bit easier.

In this tool, you select a record, and can then create parts of the formulas, and automatically the results are showing.

Using the buttons to add parts of the formulas, you get a dialog to show you what you need to add. In some cases you can open another dialog, like adding an attribute/column into the Power Fx formula:

The tool has a bit better UI than just Notepad for building XRM Tokens formulas.

This example would be a great way to use it in the Bulk Data Updater tool. You can write this small “calculation” to correct names of all contacts. Just a fast clickyclick, and it’s fixed.


Why? 🤔

Why combine these features?
Why did I develop it?
Why exists XRM Tokens when we now have Power Fx?
Why use Power Fx when I have XRM Tokens?

The combination is what takes it to next level.

The Power Fx has already grown a lot more than XRM Tokens has, and new features are added every week. So I won’t add the new XRM Tokens Format Proper since it is already in Power Fx. And a lot more of these. It’s stupid to keep track with Microsoft.

And I want to use the great features that Microsoft has created, I just want to add those things not really there from Microsoft (or any third party).

I want to add.

Using the combo of getting dynamic data together with Power Fx features is awesome.
Start imagining!


Imagination is not enough 🤯

This combo we have with three features (or whatever we might call it) gives no limits to imaginations.

These features are not just in these XrmToolBox tools – the code behind this is out there, actually right here:

https://github.com/rappen/Rappen.XTB.Helper

These open-source shared projects can be used as you wish. They are separated into three shared projects:
Rappen.XRM.Helpers mainly extension for CRMSDK (etc) that we need.
Rappen.XRM.Tokens to handle all formulas and also Power Fx.
Rappen.XTB.Helpers which is for XrmToolBox tools.
Find a short intro to the different projects here.

If you don’t need one of these, eg XrmToolBox tools library, just simply don’t include this shared project in your solution.

Use it in plugins, use it in Custom APIs, use it where you may need it!


Questions?

Contact me, or add issues or discussions on GitHub!


One thought on “Microsoft Power Fx + XRM Tokens

Leave a Reply

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