cancel
Showing results for 
Search instead for 
Did you mean: 

Better code editor and User defined functions

I think it would be a good idea to have better code editor and user defined functions/macros or what ever the name, to make the code inside PowerApps more readable and reuseable. It is errorprone to write long nested strings of commands inside a simple multiline textbox.

 

For example this is OnSelect code of a button on an app I'm developing. I'll try to explain how to make it more readable below.

 

If(CreateNew=true,Collect('[dbo].[AssignmentPermit]',{SafetyManagementPlanId: SafetyManagementPlanGallery.Selected.Id, Title: PermitTitleTextInput.Text, TargetName: PermitTargetNameTextInput.Text, Identifier: PermitIdentifierTextInput.Text, SafetyManagementAuthorizerName: PermitSafetyManagementAuthorizerNameTextInput.Text, SafetyManagementAuthorizerPhone: PermitSafetyManagementAuthorizerPhoneTextInput.Text, PermittedCompany: PermitPermittedCompanyTextInput.Text, PermittedContactName: PermitPermittedContactNameTextInput.Text, PermittedContactPhone: PermitPermittedContactPhoneTextInput.Text, AdditionalInformation: PermitAdditionalInformationTextInput.Text}),Patch('[dbo].[AssignmentPermit]',First(Filter('[dbo].[AssignmentPermit]',Id=AssignmentPermitId)),{Title:PermitTitleTextInput.Text,TargetName: PermitTargetNameTextInput.Text, Identifier: PermitIdentifierTextInput.Text, SafetyManagementAuthorizerName: PermitSafetyManagementAuthorizerNameTextInput.Text, SafetyManagementAuthorizerPhone: PermitSafetyManagementAuthorizerPhoneTextInput.Text, PermittedCompany: PermitPermittedCompanyTextInput.Text, PermittedContactName: PermitPermittedContactNameTextInput.Text, PermittedContactPhone: PermitPermittedContactPhoneTextInput.Text, AdditionalInformation: PermitAdditionalInformationTextInput.Text}));If(CreateNew=true,UpdateContext({CreateNew:false,AssignmentPermitId:Last(Filter('[dbo].[AssignmentPermit]',SafetyManagementPlanId=SafetyManagementPlanGallery.Selected.Id)).Id}))

 

Identing as a way of making code readable, what I would like to have is ability to switch line editor to auto-ident mode.

 

 

 

If(
   CreateNew=true,
   Collect(
      '[dbo].[AssignmentPermit]',
      {
         SafetyManagementPlanId: SafetyManagementPlanGallery.Selected.Id,
         Title: PermitTitleTextInput.Text,
         TargetName: PermitTargetNameTextInput.Text,
         Identifier: PermitIdentifierTextInput.Text,
         SafetyManagementAuthorizerName: PermitSafetyManagementAuthorizerNameTextInput.Text,
         SafetyManagementAuthorizerPhone: PermitSafetyManagementAuthorizerPhoneTextInput.Text,
         PermittedCompany: PermitPermittedCompanyTextInput.Text,
         PermittedContactName: PermitPermittedContactNameTextInput.Text,
         PermittedContactPhone: PermitPermittedContactPhoneTextInput.Text,
         AdditionalInformation: PermitAdditionalInformationTextInput.Text
      }
   ),
   Patch(
      '[dbo].[AssignmentPermit]',
      First(
         Filter(
            '[dbo].[AssignmentPermit]',
            Id=AssignmentPermitId)
         ),
         {
            Title:PermitTitleTextInput.Text,
            TargetName: PermitTargetNameTextInput.Text,
            Identifier: PermitIdentifierTextInput.Text,
            SafetyManagementAuthorizerName: PermitSafetyManagementAuthorizerNameTextInput.Text,
            SafetyManagementAuthorizerPhone: PermitSafetyManagementAuthorizerPhoneTextInput.Text,
            PermittedCompany: PermitPermittedCompanyTextInput.Text,
            PermittedContactName: PermitPermittedContactNameTextInput.Text,
            PermittedContactPhone: PermitPermittedContactPhoneTextInput.Text,
            AdditionalInformation: PermitAdditionalInformationTextInput.Text
         }
      )
   );

   If(
      CreateNew=true,
      UpdateContext(
         {
            CreateNew:false,
            AssignmentPermitId:Last(
               Filter(
                  '[dbo].[AssignmentPermit]',
                  SafetyManagementPlanId=SafetyManagementPlanGallery.Selected.Id
               )
            ).Id
         }
       )
   )

Commenting would be nice feature as well - I don't know if you have it already, I might have just overlooked it.

 

 

Reuseability of code could be real user defined functions or simply code blocks.

 

1. Define reuseable code block MyCodeBlock1. This is simple, not a real function as it does not need parameters. It simply functions as its code would be right there where it is inserted.

 

         Title: PermitTitleTextInput.Text,
         TargetName: PermitTargetNameTextInput.Text,
         Identifier: PermitIdentifierTextInput.Text,
         SafetyManagementAuthorizerName: PermitSafetyManagementAuthorizerNameTextInput.Text,
         SafetyManagementAuthorizerPhone: PermitSafetyManagementAuthorizerPhoneTextInput.Text,
         PermittedCompany: PermitPermittedCompanyTextInput.Text,
         PermittedContactName: PermitPermittedContactNameTextInput.Text,
         PermittedContactPhone: PermitPermittedContactPhoneTextInput.Text,
         AdditionalInformation: PermitAdditionalInformationTextInput.Text

2. So the original code would be like this.

 

 

If(
   CreateNew=true,
   Collect(
      '[dbo].[AssignmentPermit]',
      {
         SafetyManagementPlanId: SafetyManagementPlanGallery.Selected.Id,
         ReuseCode(MyCodeBlock1)
      }
   ),
   Patch(
      '[dbo].[AssignmentPermit]',
      First(
         Filter(
            '[dbo].[AssignmentPermit]',
            Id=AssignmentPermitId)
         ),
         {
            ReuseCode(MyCodeBlock1)
         }
      )
   );

   If(
      CreateNew=true,
      UpdateContext(
         {
            CreateNew:false,
            AssignmentPermitId:Last(
               Filter(
                  '[dbo].[AssignmentPermit]',
                  SafetyManagementPlanId=SafetyManagementPlanGallery.Selected.Id
               )
            ).Id
         }
       )
 

Well. Just a few ideas there.

 

Cheers,

 

Olli

 

Status: Planned
Comments
Level: Powered On

I think the biggest plus of this is the ability to create functions. This would allow users to spend significantly less time developing complicated apps, helping to make the app more useable and accessible to those who are first learning. It can be overwhelming to have three or four different places with 50+ lines of code. If you add the ability to reuse code that could be brought down to 4 or 5 lines. In addition, any software patches are significantly faster to achieve, as you can edit the code in one place and then deploy the app. This would significantly improve the speed, as well as make it more easy to debug, as there are less places for error.

Level: Powered On

I'm with @SamtecBrandonY for getting a place to put re-usable "code" so I don't have to maintain the same code in multiple places.  As for editing code, at a minimum having a floating editor that can be resized to our liking would go a LONG way.  Having the dropdown textbox that covers up the "GUI" of your app is irritating.  Plus you can see only one function at a time.  Pop-out windows could allow for multiple function windows to be opened concurrently.  BUT, ideally (since it just doesn't fit with the "citizen developer" model of PwrPlatform to give us full-on Visual Studio), could we at least get a VS Code "language extension" and a way to "strip" our code out of an app and work on it in VS Code? Notepad++ is cool and all, but if we are going for an enhanced code editor instead of a full-on IDE, VS Code seems a better candidate for integration of PowerApps.