Set canvas PowerApp date to the last day of the month

When working with canvas PowerApps, you may have a need to have some date ranges set by default. A typical scenario might be where you have 2 date filters and you want to show records that occurred between those date ranges. A scenario I had to work with recently was where the customer required the default filter dates to be the first day of the current month and the last day of the current month.

Setting a date to the first day of the month is relatively straight forward. Using a combination of the Date and the Now functions, you can set up your first day of the month variable as follows:

Set(varStart,Date(Year(Now()),Month(Now()),1))

The tricky part is getting the last day of the month. How do we know if its got 30 days or 31? What about the month of February?? What happens in a leap year!?
Turns out there is a handy undocumented “feature” when you use the Date function. If you set the day property to the number 0, it would return the last day of the previous month. So if I wanted to get the last day of February for example, my function would look as follows:

Set(varEnd,Date(2019,3,0))

Binding that variable to a date control I had, I was able to get the last day of February accurately!

date

Hope this helps.

Custom views on lookup wont work without name field

Quick tip here, when setting a custom view on a lookup in the form designer:

pic1

Always ensure that the name attribute is on the view too, even if it won’t be displayed.

pic2

I had noticed that my search results were not working at all when I had typed in the lookup field. After an hour of troubleshooting, I added the name field onto the view and voila! Search and the control, in general, started behaving.

Get the logged in users Dynamics user record ID in a Canvas PowerApp

When working with a canvas PowerApp that integrates into Dynamics 365, you occasionally need the current users’ Dynamics user GUID. This could be used to populate lookup references on the various records within Dynamics.

The user details provided by the User function within a Canvas app relates to the Office 365 user account of the logged in user. We know that for a single user, who has access to multiple Dynamics environments, there is no guarantee that their Dynamics user GUID would be the same in those environments. The Office 365 account/credentials used to access these various environments is the same however. With this in mind, this is how I get the logged in users Dynamics GUID.

  1.  Create a data source connecting to the Dynamics Users entity
    alt
  2.  Get the current logged in users’ profile, using the PowerApps user function, and create a variable placeholder(considered best practice to store it in a variable):alt
  3. Query the User data source, created from Step 1, and filter on matching the domain name on the user record to the current users’ email address and return the ‘systemuserid’ property i.e the user’s Dynamics 365 user GUID

alt

You can then add a label, for testing purposes, on your canvas app and bind the text to the variable above to ensure that it’s worked correctly!

This has always worked for me but I’m keen to know how others have catered for this scenario so if you have done it before or have some ideas, let me know!

Episode 2 – Money in the bank with PowerApps

[vc_btn title=”Back to the Video Library” color=”warning” link=”url:https%3A%2F%2Fdynamics365society.uk%2Fmicrosoft-video-library%2F|||”]

In these episodes, I will look to show how you can use canvas apps to leverage existing functionality within your Dynamics environment more efficiently which in turn allows you
to save money to put back in your bank account.

This episode focuses on the need to provide quotes quickly to customers



source

Episode 1 – Money in the bank with PowerApps

[vc_btn title=”Back to the Video Library” color=”warning” link=”url:https%3A%2F%2Fdynamics365society.uk%2Fmicrosoft-video-library%2F|||”]

In these episodes, I will look to show how you can use canvas apps to leverage existing functionality within your Dynamics environment more efficiently which in turn allows you
to save money to put back in your bank account.



source