Vue normale

Il y a de nouveaux articles disponibles, cliquez pour rafraîchir la page.
À partir d’avant-hierFlux principal

Clone a single record from Command bar using Power FX Formulas

Power Fx is a low-code language that makers can work with directly in an Excel-like formula bar or Visual Studio Code text window.

Power Fx are the main coding language in Canvas apps and have been extended to Model Driven apps as well to be used from the Command bar to execute actions in addition to JavaScript, and is used as well as a new column type similar to calculated columns.

In this quick article we will see how we can clone a contact record directly by clicking a button on the form command bar:

  1. Add your model driven app in a solution and open
  2. Navigate to Pages->Contacts View-> Click the 3 horizontal dots and choose Edit Command Bar ->Edit

3. Select Main Form and click Edit

4. Select New -> New Command from the commands left Navigation.

5. You will be promoted with a question whether you want to create a Power FX command or JavaScript for Power Fx it will need to create a component library to enable you to use the Power FX formulas -> Choose Power FX and click Next

6. Give you new command a label “Clone Contact“, in the Action shows to run Formula and you will see the Formula Bar is opened by default on the On Select Event, you can also change the visibility to run based on a formula

7. For the actual command we need to use the very popular Patch function and the key thing here is how to access the fields in the current form so it is very easy using the below expression:

Self.Selected.Item

This expression gives you access to the current object and then you can access the fields easy as

Self.Selected.Item.'Last name'

The below command will be cloning the first name, last name and company name which is a lookup to the account table.

Patch(Contacts,Defaults(Contacts),{'First name':Concatenate("copy",Self.Selected.Item.'First name')},{'Last name':Self.Selected.Item.'Last name'},{
    'Company':Self.Selected.Item.'Company'
})

Note:

I could not make it work till now using Composite/Polymorphic Look ups like customer!

It is working perfectly in less than 10 minutes you could clone a record very easily!

Happy Low Code Development!

References:

https://learn.microsoft.com/en-us/power-apps/maker/model-driven-apps/commanding-use-powerfx

How to use Power Apps named formulas (experimental feature)

Recently Microsoft announced a new experimental feature in Power Apps: Named formulas

Named formulas in summary are, defined functions without parameters, that can be reused anywhere in a Canvas App.

What are the advantages of using Named formulas instead of global variables (defined with ‘Set’)?

The formula’s values are always available, there is no time dependency as it happens on App.OnStart (if you enabled delayed start, some variables might not have been populated when you try to access their values).

Formula definitions work like constants, they need to be defined in the App.Formulas property and cannot be updated anywhere else in the app

Also, the formula’s output values are only calculated when needed, which will speed up app loading times if you defined a lot of them in the App.OnStart event

How to use them?

Enable Named formulas under experimental features (authoring version 3.22091):

After enabling the feature and reloading the app, add your formulas to the App.Formulas property. You can even add objects as named formulas, for example, if you had an object variable that you used to store all colours for the app and work as the ‘app theme config’ variable, you can convert it to a named formula:

Call or reference them as if they were global variables from anywhere in the app (except for using ‘Set’, so for example Set(myFormula,”Value”) would not work.

In the example below we are using a reference to a named formula to define the button fill color:

And below using a reference to a record to retrieve the last item submitted by the current user. This would also return the latest item Id as the formula values are always up to date, and we don’t need to worry about refreshing their values as we do with global variables:

Conclusion

By using the named formulas feature you can speed up your app’s loading time in case you had a lot of global variables defined on the App.OnStart event, while enabling functions that are read-only and will always have their return values up to date.

The post How to use Power Apps named formulas (experimental feature) appeared first on michelcarlo.

❌
❌