You don’t know how to rename inspection templates.

One of my clients has the Field service installed on their Dynamics and they use it quite extensively. Lately, they were trying to tidy up their inspection template library they’ve built over the years and came up with a really simple request: How to rename an inspection template…

TLDR: There’s no easy way to rename the inspection templates

You need to change the name in the following places:

  • Inspection template version entity (msdyn_name)
  • Inspection template version’s JSON definition (title field)
  • Inspection template’s msdyn_name

I used a Microsoft PowerAutomate Flow to update the records and update the JSON. See the solution below.

This should be a simple one…

…I said to myself. Then I searched through the interface. The “Title” field was read only, and I couldn’t find any other option to rename it.

What now… Well, let’s see how the name is actually stored in the entity… I used the LevelUp extension (which I highly recommend) to check all field values:

It looked like it was the msdyn_name field I needed to change.

I created a new flow in PowerAutomate to be triggered when a row is selected.

What did not work

Initially I just tried to update the msdyn_name on the inspection template version, which worked until I published a new version. So I figured that the system must be updating the msdyn_name when the version is published. I checked the values again and I saw that the actual Inspection Template definition is stored in a JSON format. It’s encoded first to URL encoding (to capture any UTF-8 characters) then to Base64. In the database, it’s stored in this encoded format.

The name didn’t propagate to the inspection template itself as well, so I needed to update it separately.

I also learned more about how the inspection template versioning works:

  • When you click “Revise”, a new inspection is created on frontend (see the POST request body below)
  • Then when the user wants to publish, the client just updates the msdyn_state to 1 (Published)
    • Looks like there’s a plugin waiting for this event. This plugin then deletes the latest published version

The final solution

So I prepared a flow, which looks like this:

Step 1: The trigger. I ask for the new name here:

The trigger only returns the ID of the inspection template, so I have to retrieve the actual template information.

Nothing fancy here, apart from the fact that the GUID field is called “InspectionDefinition”, which is probably what it was called before (Inspection Definition).

Then I needed to get the JSON data to change the field there. As I mentioned earlier, the JSON data is first encoded with base64 and then with URL encoding as well. I used the Compose block with the following formula to get the plain object, which I can manipulate:

json(
    uriComponentToString(
        base64ToString(
            outputs('Get_a_row_by_ID')?['body/msdyn_jsoncontent']
        )
    )
)

Then I used the setProperty expression function to change the title in JSON.

setProperty(
    outputs('Get_the_JSON_Content'),
    'title',
    triggerBody()['text']
)

The code gets the JSON I just parsed, changes the ‘title’ property and assigns it the value, which I get from the user (triggerBody…)

The JSON is now done. Let’s start with the updates…

First, I’m updating the Inspection Template itself. I just need to update the name here:

Then I’m ‘revising’ the Inspection Template version by creating a new one:

The important part is the “Status” field, which is set to Draft.

I’m copying most of the data here (Description, Effective Date, Has Required Question, Inspection Template, Version). The Name field is set to the new title.

Now for the JsonContent part, I’m using the following formula to encode the JSON back in its original format:

base64(
    uriComponent(
        outputs('UpdatedJson')
    )
)

Finally, I can publish the template version:

I’m just setting the status to published here, because the plugin will take care of the rest.

Conslusion

This is just another example where “It’s a simple one” was a huge lie. I’m not sure when I’ll learn not to trust these words, but I’m still optimistic.

As much as I’m annoyed sometimes by Microsoft’s Power Automate, it’s a really handy and powerful tool, which you just have to get used to.

Share this article
Shareable URL
Prev Post

Warp-speed your flows – use range(), Select and Filter

Next Post

Documentation: How to stop hating it and embrace its potential

Read next