PACX ⁓ Init custom tables main form

Riccardo Gregori - Oct 11 - - Dev Community

When I'm working on Model Driven Apps or Dynamics 365 Customer Engagement, one of the most annoying things I have to do every time I create a new custom table is to fix the table main form 😒.

"Fix"? What do you mean?

The out of the box form comes out like this:

Out of the box form

As you can see, there is one single tab, with one single headless section, containing the primary field and the owner field. The tab has no name. If you select just the section, you'll see that also the section has no name.

Out of the box form with selected section

Moreover, important fields such as Created By, Created On, Modified By and Modified On, that are really useful to get a visible feedback on the record history, aren't placed within the form.

What I always have to do is:

  • Set a name on the first tab (tipically, tab_general, following the pattern tab_ + tab title all lowercase without spaces)
  • Set a name on the included section (tipically, tab_general_sec_general, following the pattern parent tab name + _sec_ + section title all lowercase without spaces)
  • Remove the Owner field from the section
  • Add a second tab called "Administration" (tab_admin) with a single headless 2-column section (tab_admin_sec_admin), containing Created By, Created On, Modified By, Modified On and Owner fields, with a nicely aligned layout.

This, for all the custom tables I create 😤.

PACX to the rescue! 🚨

Just a couple of days ago I had to do it for 10 tables in a row for a solution I'm setting up... too much manual work for a lazy guy like me.

Then I thought: "What if the same time spent on doing that manually, I'm gonna spend it writing a PACX command that does the same stuff automatically?"

After a couple of try-and-error (really helpful lessons learned) the new command is born: pacx forms clean.

pacx forms clean

The command does exactly what described before:

  • It sets the name attribute on each unnamed tab, starting from the tab label
  • It sets the name attribute on each unnamed section, starting from the parent tab name and the section label
  • Removes the "Owner" field from the first tab, if present.
  • Creates a new tab called "Administration", with a single untitled 2-columns section, containing "Created On", "Created By", "Modified On", "Modified By" and "Owner" fields.

And the result is:

Output 1

Output 2

Output 3

But... how does it works? 🤔

I've tested 2 different strategies to update the main form.

The first one was to:

  • read the formxml directly from the Dataverse systemform table
  • update the XML in memory
  • update the systemform record with the updated XML

But I've realized that on the systemform table there are 2 fields representing the form structure, formxml and formjson, and I've seen that a direct update of the formxml field didn't get reflected on the corrisponding formjson, neither after a publish... so I had to try a different path.

For the second try I took inspiration from the Ribbon Workbench approach (thanks JVE for the hint, and Scott Durow for the awesome tool). The solution was to:

  • Create a temporary solution
  • Add the form to the temporary solution
  • Download the temporary solution
  • In memory
    • Unzip the solution
    • Extract the customizations.xml file
    • Manipulate the formxml within the customizations.xml file
    • Repack the zipped file
  • Then re-upload the solution and publish
  • After all, delete the temporary solution

Et voilà, les jeux sont faits.

🔍 If you're interested on internals you can take a look at the source code.

📦 The command is available on PACX version 1.2024.10.153 or above.

. . . . . . . . . . . . . . . . . . . . .
Terabox Video Player