Editing Command Bar in Model Driven Appswith Power FX 2

This post is part of the Dataverse series.


Component library

In the last Command Bar post we have added a new Power FX Button to the command bar on the Main menu. Now, let’s have a look what we can do in addition.

  1. Open the Solution, in which you have created the new command.

  2. Some new artificats have been added to the solution - we will focus on the Component libraries.

  3. Inside the Component Libraries you will find your new created Modern Command.

  4. Click on the ellipsis (3 vertical dots) for your component and select edit, to open the command editor.

  5. When the editor is opened, you will see in the Formula bar your code. But in this window you also have additional functionality. Especially you can add additional datasources. Therefore, have a look at the left pane, select the data icon and select add data.

  6. Search for e.g., Tasks and add the Dataverse Tasks table to your command.

  7. Click save and publish and close the component library.

Command bar editor

Now, let’s navigate back to the screen, where we have created the Marketing command button where we just have added an additional data source:

  1. Inside your solution
  2. OPen the Model Driven App
  3. Navigate to the table (Account) in the left menu
  4. Click on the 3 dots on Account view and select Edit command bar
  5. Open the Main form and select the Marketing Button
  6. Open the formula bar and add the following code before the Notify formula Patch( Tasks, Defaults(Tasks), {Regarding:Self.Selected.Item}, {Subject:“Marketing Follow up”} {‘Due Date’:DateAdd(Self.Selected.Item.‘Modified On’,7,TimeUnit.Days)} );
  7. If you like you can adapt the Notify dialog as wwll
  8. Save and Publish & click Play to test

Let’s have a look at the above code

  • As we have added the tasks to the data of the component, we can leverage the information about the task table.
  • You can use Concurrent to run multiple formulas synchronous. In my case I will not use concurrent, as I want the Account patch to be finalized. the, the next patch to create Tasks can use the modified on date to calculate the due dtae of the follow up.
  • To create a new record in a different table, use Patch(RelatedTable, Defaults(RelatedTable, {PropertyRelatedTable1:Value or formula},{PropertyRelatedTable1:Value or formula}))
  • If you want to calculate a date, you can use e.g., DateAdd. In Dataverse there are different types of Date fields available. You can have Only Date, Date and Time, but date fields can also have different Timezone Settings. Unfortunately calculation with Now / UTCToday is only supported with Timezone independent setting. Therefore it is better, to use an already existing date field, that has been set already to do the calculation. This is the reason, why I am doing the Patch one after another, so I can leverage the modified on which has just been updated in the previous step.

All parts of this series (21)

  1. 1. Copilot for Dataverse - New experience
  2. 3. Copy an existing Model Driven App
  3. 4. Editing Command Bar in Model Driven Appswith Power FX 2
  4. 5. Custom Pages in Model Driven Apps
  5. 6. Editing Command Bar in Model Driven Appswith Power FX
  6. 7. Dataverse Teams Integration - External Content
  7. 8. Dataverse Email Integration
  8. 9. Manage Polymorphic Lookups in Dataverse with XRM Toolbox
  9. 11. Mapping columns in related Many-to-Many tables
  10. 12. Mapping Lookup Columns
  11. 14. Best Practices when working with Dataverse
  12. 15. Create your own M365 Dev Tenant
  13. 17. Activate additional languages in Dataverse
  14. 18. Publishers and Solutions
  15. 19. Tables and Columns
  16. 20. Datamodelling in Dataverse
  17. 21. Introduction to Dataverse