cancel
Showing results for 
Search instead for 
Did you mean: 

Create custom functions / macros

Could we have the ability to create a custom fucntion for a PowerApp.

 

For example if I had the following function

 

CountRows(Filter(Request, CurrentStatus = "New Request", SiteTypeGallery.Selected.SiteTypeId = ParentSiteType.SiteTypeId))

If wanted to use it for different types of status, it would be good to be able to create a custom function / macro somewhere called StatusCount that takes two parameters status and sitetypeid. This would make it cleaner and also save have to go through each of the controls that use this to udate it if the condtion changes.

Status: Under Review
Comments
Level: Powered On

Finding that I am using the same old function code again and again. Crying out for macros to stop app formulae becoming unmanageable. Code (formulae) re-use is needed, just like in Excel.

PowerApps Staff
Status changed to: Under Review
 
Level: Powered On

+1,000,000,000,000

I'm tired of cut and paste and spending hours to just to add the same code to multiple controls!

Please give us functions!!!!

Anonymous
Not applicable

Need this too.....

Level 10

STRONGLY need either ability to define functions or macros within PowerApps.  Functions would be preferred for efficiency (as code technically isn't duplicated), but macros (in the "C" style allowing parameters) would be sufficent. 

 

This is probably the #1 issue with being able to do anything serious within PowerApps without extreme frustration.  No having macro of function support causes the following issues:

 

  • Lack of code reusability - in any reasonable manner - Have to constantly cut and paste complex filters, etc every time they are used.

  • Lack of code maintainability - Having to cut and paste the same (or roughly the same) code throughout the application every where it is needed makes it almost impossible to maintain that code (of course not having any way to search for code within the editor in order to try to manually change things makes it exponentially harder as well on top of this).  ie: if there was an error (or enhancement) in one section of code, one has to manually find it (no search), and manually replace it everywhere.
  • Extreme user frustration when creating applications with PowerApps - Due to the above (and just overall time wasted), inability for code reuse/macros really makes PowerApps a difficult environment to create an application with any level of complexity in - and for all its benefits - really does make one want to switch to another solution (I'm seriously considering it in the future).  

BTW - understood that one can user Azure functions and Flow (which I do at times) to partially handle some of this - but this should be unnecessary.  It also requires one to develop those functions within a DIFFERENT environment with a different language (not to mention additional licensing - not an issue for us as we use Flow as well, but definitely something to consider).  Note that this also would NOT address reusability of code for things like Filters in galleries, etc.  Something that could easily be addressed with a macro capability.

 

Having macro capability in PowerApps would promote the non-developer goal of PowerApps - as in most organizations a non-developer would have to go throught their IT or Dev organization to get these Azure functions or Flows created, even for something simple.  

 

 

BTW - not the best workaround, but one way that works to some degree is to create a Button control (possibly hidden) and on its OnSelect property, put the code you want in your "function".  It would need to reference specific Context Variables, global variables, etc as "parameters". 

 

Then you can call Select(ButtonName) every time you wish to call that function.  I'd imagine you can do this with other controls that also have an OnSelect property (like a Text control) - would give you the ability to "cache" data in the control itself (ie: in the "Text" property of the text control if you wanted).  

 

 

Two (big) issues with this workaround:

 

  • Select() can only be called on a control that is on the same screen - PowerApps prevents you from calling Select() on a control from another.  Only way around this is to Navigate() to that screen, passing it parameters to tell it to call Select() for you, and then the execute a Back().  I've done this a bit and it works fairly well (except for next issue), but still is more work than required and does cause the user to see the brief screen transition away and then back.
  • Select() does not block until the OnSelect() function executed - (and really this is correct behaviour, though not for what this workaround attempts to do).  This means that when you call Select() any code after it that depends on what OnSelect() is doing to be executed cannot assume that OnSelect() has not completed (in fact, if it does anything like load any resources - its almsot guaranteed to not be completed).  

    And since there is no direct way to wait on something else being done (no true semaphore, WaitForSingleObject(), WaitForMultipleObjects() functionality), this is problematic.   

Macro functionality is HIGHLY desired and would GREATLY promote code reusability, application maintainability, and user happiness (replacing the extreme user frustration for not having this).

Level 8

What @BrianR said... I couldn't add anything to this superb post - thanks!

Level: Powered On

How to create custom functions and use them in multiple controls ?


Level: Power Up

Looking to adopt Powerapps for some clients and this is a real factor. Can't dedicate professional developers to something so rudimentary as to not allow code reuse