August 19, 2021

Power Automate Desktop and PDF Actions

Every month I receive my utility bill and because my supplier doesn't provide a way to pay it online, they send me a PDF with all the usage details including a page to pay the bill. It uses a system in Italy known as "Bollettino Postale", it can be paid in person in post offices or online (Poste Italiane website).

Because I pay it online I need to manually copy some information from it (amount, payment reference, ...) and fill a form. It takes me few minutes to do but inside the PDF I receive this "bollettino postale" is not horizonal but vertical, when you need to be sure that you copy some numbers rotating the head is not the best approach :)
So I asked around and my friend Joel Lindstrom suggested to check Power Automate Desktop because it has some PDF actions, like extracting a page from a PDF. The page that I need to extract and rotate is usually the last one.
Sadly Power Automate Desktop doesn't have the actions I need, so I searched and I found this idea regarding the page count (PLEASE UPVOTE IT !!!)

It should not be a difficult action, you provide as input the PDF file and it should return a variable containing the number of pages, in this way I can extract the last page or the previous one. There are some workarounds (like this one) but an action would be simpler.

My second requirement is to rotate a PDF (or a single page of it), I didn't find an idea so I created one (PLEASE UPVOTE THIS AS WELL !!!)

Rotate PDF Clockwise or Counterclockwise

I found that I am not the only one with a similar need (like this post), of course this is more complicated than just counting the pages but if they provide a way to rotate all the pages (instead of just a specific one) it could be beneficial.

So if you like these ideas please upvote them and if you have an idea check if someone else suggested it first and in case create it.

Personal note: there is a way to automatically pay utility bills with a bank account (like I do with my internet provider) but for this supplier I prefer to pay manually.

May 19, 2021

Writing plugins and If conditions

This may be a silly post but it's something bothered me enough to write it down, so I just start with a disclaimer:

if you are using a tool or some code to assist you writing a plugin go for it, this post is not about this.

Few weeks ago I watched a YouTube video about programming, it described the advantages to don't write else conditions, I don't recall the exact remarks but was something like this, so instead of writing:

if (condition == true) {
} else {

the author suggested to write something like

if (condition == true) {
if (condition == false) {

I don't agree by principle, some comments suggested that a switch can also be used, in the example the author probably put some else if statements and one thing I don't like is definitely else if.

Today I wrote a plugin, as usual I copied the wireframe from one that I previously created and I implemented the logic. It was working but the final part of my code was just a long list of closing brackets of several if conditions I had in the code. So I remember the YouTube video I watched and I told myself: Can I rewrite this plugin to avoid a concatenation of if conditions?

Usually my wireframe looks like:

if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity) {
   Entity entity = context.InputParameters["Target"];
   if (entity.LogicalName == "account) {
      if (context.PostEntityImages.Contains("PostImage") && context.PostEntityImages["PostImage"] is Entity) {
          Entity postImage = (Entity)context.PostEntityImages["PostImage"];
          // rest of the code
When you start with this kind of style (copied from official documentation or tutorials) it's easy to follow the same structure, you go for the true path, and in the last if condition the main code is executed or else it fails, the majority of the previous if we don't care, because the plugin logic should probably be skipped.
Inside a plugin I usually forgot that I can use return if I want to close the plugin, it doesn't go to an error, just the main scenario should not be executed.

So I rewrote the plugin reversing the conditions, so my code looked like:
if (!context.InputParameters.Contains("Target") || !(context.InputParameters["Target"] is Entity)) { return; }
Entity entity = context.InputParameters["Target"];
if (entity.LogicalName != "account) { return; }
if (!context.PostEntityImages.Contains("PostImage") || !(context.PostEntityImages["PostImage"] is Entity)) { return; }
Entity postImage = (Entity)context.PostEntityImages["PostImage"];
// rest of the code     
One thing I noticed reversing the conditions is that I use often !string.IsNullOrWhiteSpace to check if a value is not empty and continue, inside this plugin I used string.IsNullOrWhiteSpace with a return (meaning I exit if the value is empty), made me curious to know which syntax the author(s) of this method may like.

Just a note, in the code I wrote above I retrieve the Image by name, my friend Daryl LaBar taught me that you can just check the existence and access the first item of the collection, because normally you register a single Image against your step.

This post is not a best practice one or similar, just writing down the thoughts I had in mind today.

May 8, 2021

Microsoft.PowerPlatform.Dataverse.Client and ClientSecret AuthType

.NET Core 3.1 is what I consider a good starting point if you plan to create a new project based on .NET Core, it's LTS (until end of 2022) and if you developed only with .NET Framework before, I usually suggest this version.

I know .NET 5.0 has been released for some months now but for what I am describing here it's not important, if you wish you can use this version.

If you are a developer and in the last years you worked with Dynamics CRM/CDS/Dataverse you probably know this NuGet package:

It's the package we usually install when we need to connect to Dataverse, it works but requires .NET Framework 4.6.2 or onward. It works also with ClientSecret AuthType, if you have this kind of connection string

AuthType='ClientSecret'; ServiceUri='';
ClientId='00000000-0000-0000-0000-000000000000'; ClientSecret='MyWonderfulClientSecret';

or if you are using Username & Password you may have something like this

AuthType='Office365'; Url='';
Username=''; Password='MyWonderfulPassword';

In your code you can connect with few lines:

CrmServiceClient service = new CrmServiceClient(connectionString);
WhoAmIResponse whoAmIResponse = (WhoAmIResponse)service.Execute(new WhoAmIRequest());
Console.WriteLine($"Connected with UserId: {whoAmIResponse.UserId}");

CrmServiceClient comes from the namespace Microsoft.Xrm.Tooling.Connector.

What if we want to use .NET Core? The NuGet package to use is currently in public preview:

You can use this package also with .NET Framework and .NET 5.0 but the main reason is the compatibility with what we call .NET Core (and if you still want to say something like "but with .NET 5.0 we can bla bla bla" fine for me, also with .NET Core is possible to use .NET Framework packages but we would make the executable only compatible with Windows, I never suggested that kind of path but it's a possibility).

This package is not compatible with the Username & Password authentication, as stated inside the description: Note: that only OAuth, Certificate, ClientSecret Authentication types are supported at this time.
Meaning it's also a good time to move away from old forms of authentication.

Assuming you have a connection string with the ClientSecret AuthType how would our code changes? Just a type:

ServiceClient service = new ServiceClient(connectionString);
WhoAmIResponse whoAmIResponse = (WhoAmIResponse)service.Execute(new WhoAmIRequest());
Console.WriteLine($"Connected with UserId: {whoAmIResponse.UserId}");

ServiceClient comes from the namespace Microsoft.PowerPlatform.Dataverse.Client, that is also the name of the package, so make sure you are using it.

Hopefully next time I will remember that is called ServiceClient and not CrmServiceClient, DataverseClient or PowerPlatformClient, types I tried before checking what was inside the package.

March 10, 2021

Power Automate Desktop, opinions of others

Few days after the announcement of Power Automate Desktop for Windows 10 users (official link here) a famous Italian website focused on IT released a brief news about it (link here).

Microsoft is a big name so it is normal that something regarding Windows 10 made the news also inside this site (for example they published also the Microsoft-Bethesda agreement) but I was more interested in the comments.

First some numbers, the article contains 17 comments, I checked the recent news and except an article about Tesla Cybertruck (with 35 comments), the Power Automate Desktop one was the most commented (usually there are between 6 and 10 comments in other news).

This is very good in my opinion, people read the news and after wanted to discuss it, but what they are talking about?

A couple of comments are about the comparison to Mac (Apple Script is mentioned and the fact this is is coming to Windows years later), no surprises here, I also mentioned this in my previous post.

A user asked if can save something to PDF, rename it and after move it to a specific folder, another user promptly replied that is possible, that he is also checking the software and it looks useful.

Another user wrote that he downloaded the software, that is complex (meaning that you can do many things) and reported that maybe for his daily activities is not useful but he would like to check some demos.

Another comment was that in the download page there is the "Download now" option and "Buy" option, this made him confused.

A couple of users (in order to explain to others) compared Power Automate Desktop to IFTTT or to a Macro system.

Last comment was a bit more technical, the software was always intended as Business oriented, Powershell is also available for some automations under Windows.

In the end was good to see how this kind of product is received to a bigger audience, most of the comments were positive and they confirm my initial thought, having Power Automate Desktop included inside Windows 10 can be very beneficial.

March 3, 2021

Power Fx and Power Automate Desktop, my opinion

Microsoft announced a couple of things regarding Power Platform, Power Fx and Power Automate Desktop for Windows 10 users.

I start with Power Fx, you can find a couple of posts here:
Introducing Microsoft Power Fx: the low-code programming language for everyone
What is Microsoft Power Fx?

I am happy the language used in Canvas Apps got an official name (and it will be Open Source too) but I am not surprised, sooner or later (just for Documentation purposes) you need to call this agglomerate of functions in some way, so people can easily check or ask questions about it.

I am also happy that the code behind a Canvas App can be easily stored inside a source control system but let's be honest, nobody in a clear state of mind would be happy to edit that kind of YAML files directly :)

For how long we will continue to talk about low-code, citizen developers and stuff like that? When I was younger I developed applications with Visual Basic 6, I am sure that people developing in C++ thought about Visual Basic like it's a toy or something similar, the reality is that who used Visual Basic was probably a developer with less knowledge than the average C++ developer, nothing to be ashamed for, because there is a difference if I need to create a Windows driver for a PC component or a Windows Forms application to manage my customers.

As much as I appreciate the games developed by Scott Durow for Canvas Apps, using just a specific option (like a Canvas App or a writing a plugin) because it's technically possible should be (in my opinion) avoided. Like writing a 1000 lines of code plugin instead of 3 blocks inside a flow, or creating the biggest flow on earth just to avoid a 10 lines of code plugin. I think less of who write code in Canvas Apps? Definitely not, I call them "citizen developers"? Definitely not, if you know how to develop good for you, if you found a tool that encourage you to write better and lesser code good for you. For me Power Fx is not a low-code language, it's just a code language, like C#, JavaScript, VBA Macros, etc etc. Why I say this? because I can be proficient in one of the most common code languages, but I am sure that there are plenty of developers (maybe proficient in Assembler) developing more complicated stuff than I do. But the moment we write some code we are all developers, that's matter.

Moving to a more interesting topic, the new release of Power Automate Desktop for Windows 10 users is an AMAZING news. Announcement post:
Automate tasks with Power Automate Desktop for Windows 10—no additional cost

This is a game changer for Windows, if you are familiar with Mac, it is comparable to what Automator does. I quickly downloaded the application (link is and it's really something users should try.

Check this screenshot:

These are the actions related to FTP, imagine that your security camera saves the files in a specific FTP site and you want to copy automatically that files to a local folder (maybe synced with OneDrive), no manual steps, you can just create the automation and launch it.
Having a tool like this included in Windows will make users more familiar with the technology itself and the possibilities it offers, this means that when a user will need to automate some tasks in a work environment, already has the experience to do this kind of tasks.

Next time I need to create a repetitive task, I will definitely check if I can do it using Power Automate Desktop first.

November 11, 2020

Few words on Dynamics Weekly

If you were a subscriber of my newsletter Dynamics Weekly you already know I decided to don't continue it a month ago. After the final issue I received many messages of support from the subscribers, I tried to reply to each one of them and if I missed someone I am really sorry.

149 issues can be a strange number to close, someone on Twitter suggested me to arrive at least to 150, but more than being an even number I don't see other reasons :) However #149 was the first issue of October 2020, meaning it contains the HR content of the previous month. I don't check analytics, but I didn't want to interrupt something "on the middle", closing the newsletter with this content was the right thing to do for me and to respect the effort of Malin to prepare that part.

Why you closed the newsletter? Reason is quite simple, I didn't want to run it. You may consider this reason selfish, but during September my main thought was how much I was tired by Dynamics Weekly and that I didn't want to run it. Of course I was tired during other times in the past but I always wanted to continue it. To don't want to run the newsletter was a new feeling, and when for several days you get up and you go to sleep with that thought, you understand that what you are doing is not healthy.

Why don't take a break and continue later? Dynamics Weekly was out every Monday, no matter what. Jonas helped me in the past, this time I felt that after a break I would not be able to resume it and I didn't want to force myself to do something I don't like, I really like Dynamics Weekly and I didn't want to hate it.

Why don't pass the torch to someone else? When I started the newsletter I didn't ask others for suggestions or ideas. I was a subscriber of other newsletters so I knew how it works, I registered the domain, I paid the first month for the service and I sent it. As I wrote in the past it was something I needed for myself in the first place, it's the way I like to consume and keep track of information on some topics. I could ask someone else if they want to continue it but I didn't want to be a burden or for them to don't feel uncomfortable if they need to take decisions I may or I may not like, for me Dynamics Weekly is a closed chapter.

What do you think of other Power Platform newsletters? Running a newsletter where you curate the content is time consuming, and everyone involved has my respect. When I started there was no newsletters on the subject (that I know of) and now I am happy that there are two: Power Platform Developers Weekly and Power Platform Weekly. If you like the topics subscribe to them or (and I really appreciate this choice as it was one of the things I liked about Dynamics Weekly) go to their websites and check the issues directly there.

What about PCF Gallery, do you plan to close that too? No, PCF Gallery doesn't require the amount of time I gave to Dynamics Weekly, some weeks more controls get published, some weeks no controls at all. Beside the improvements that I didn't implement yet (sorry about that), I am aware the website should not be managed only by me, I hope to improve this aspect too in the future.

September 13, 2020

Dependent Option Set Manager

tl;dr: Dependent Option Set Manager Solution (DOSM) can be downloaded here, check the demo here.

First of all, if you contacted me in the past about my previous Dependent Option Set solution and you didn't get an answer I am really sorry.
Only recently I noticed comments on this blog went directly to spam and some of them were about Dependent Option Sets, when I get messages on Twitter or LinkedIn I usually get an email notification and it's easier for me to track them.

Latest release of my previous Dependent Option Set solution was more than 2 years ago, I know it wasn't perfect but the main goal was to easily generate the required JSON, the fact that included also the script to add the functionality to a form was always secondary, I just tweaked the original script to be compatible with more Dynamics versions and with the latest release to make it compatible with Multi Select Option Sets.

If you used or still using it in some projects I am really happy for you, it means it was useful. I am not here to argue or pick a side compared to Filtered Lookups, it happens that sometimes you have Option Sets instead of Lookups (probably the main advantage is the translation of options) and it was nice to provide this functionality.

Microsoft announced Dependent Option Sets before, and I replied to someone asking me about improvements with "Microsoft will release Dependent Option Sets, I don't think I will update my solution". After a while I noticed that Microsoft removed this announcement and my solution (I repeat here, main goal was to generate the required JSON) was still used. In the last years I focused on other projects (Dynamics Weekly and PCF Gallery), I already write code during my working hours and I didn't want to write (crappy) code in public projects. Despite this, I always recognized that my Dependent Option Set solution was used and sooner or later it deserved an update.

I finally decided to spend some time on creating something new and I released Dependent Option Set Manager (DOSM), an updated version of my previous solution. Main reason of this release is the use of formContext instead of the old Xrm.Page, Unified Interface transaction is near (some customers are already using it) and it's nice to provide a fully supported version of the script.

But I wanted to do more, I thought: "How this should work for me?", upgrading the previous JavaScript to support formContext instead of Xrm.Page took me few hours, I changed some parameters, wrote some code and it was ready.
This way still require people to go manually on each form, make the changes, save and publish the form, if you already configured the previous script it's not difficult but it's a tedious process.

I wanted to provide an upgrade path, so people would install the new solution and at least they would have an option to update the forms in one way, and after I wanted to allow users to configure new options, to create new JSON Web Resources and so on.
In the end the new solution has many features so users can do everything inside the app

This forced me to work also on the script attached to the form. Yes, it works in a similar way as the script provided by Microsoft (practically an OnLoad event to load the JSON and an OnChange event for each parent field) but in addition to the code to deal with Multi Select Option Sets and the new features it's something now rewritten by me.

What are these new features?
  • Sorting, you can now decide how the values inside the Option Sets should appears (for example by Label or by Value).
  • Multiple parents, now if a Child Option Set has more than one Parent Option Set, the available options are only the intersect (quick example, for one parent the child options would be A and B, and for another parent options B and C, the only option available would be B).
Solution also included some fixes:
  • It will not trigger when a form is Disabled or Read Only (like inactive records).
  • There was a bug when more than 2 option sets were in a chain and child Option Sets were not cleared when the parent changed.

If you want to try/use the new solution you can go to the Releases under the GitHub repository to download it, and a for a demo here.

The license is MIT, means that the solution is provided "as is", no strings attached, I also tried to make clear this with the notice I wrote inside the tool:

Yes, the code is fully supported, but when dealing with Dynamics XML Forms it's a bit complicated so I needed to make you aware of that warning.

Now regarding support, if you have questions or you have problems with the solution, please open an issue here:
It's better than contacting me directly because
  • I usually get an email when a new issue is opened
  • It's all public so everybody can see it
If in the future Microsoft decides to implement Dependent Option Sets, I only hope they will make an API available, so I can build some tool to convert my solution to the Microsoft one.

The code is public and I tried to make it as much readable as I can, there are many comments both in what the functions do and the code itself.

DOSM uses the following libraries (for the app, the Form script does not have dependencies):
  • jQuery 3.5.1
  • Bootstrap 4.5.0 (I know it's currently 4.5.2 but I didn't feel necessary to upgrade it)
  • Bootbox.js 5.4.0 (to deal with Bootstrap modals)
  • bootstrap-select 1.13.18 (I made a change on this library, the one you find inside DOSM is not the same as you download it, more details in this issue I opened in their repository)