Introduction
In our previous blog we have explored on how to set date and time fields of dynamics 365 through power app. Handling date and time fields according to time zone is quite tedious task. In today’s blog we will explore more on how to handle date and time fields of dynamics 365 according to user time zone in power apps.
The time zone of dynamics 365 instance is set as “Eastern Time” as shown in below screenshot:
But my app is running on the phone where time zone is set as “Indian Standard Time”.
Therefore, we cannot set correct time in the date and time fields due to time zone difference between dynamics 365 and powerapp.
To solve this difference, follow the below steps for updating the date and time fields of records in dynamics 365 through power app:
1. Create a default Canvas app for appointment entity by using Dynamics 365. You can refer our previous blog here
2. Now add “Start Date” and “End Date” fields on the edit screen as shown in the below screenshot:
3. Now on “onSelect” property of “IconAccept”
add patch formula as given below:
Patch(
Appointments,
First(
Filter(
Appointments,
activityid = BrowseGallery1.Selected.activityid
)
),
{
scheduledstart: If(
IsBlank(DateValue1.SelectedDate),
Blank(),
DateAdd(
DateValue1.SelectedDate + Time(
Value(HourValue1.Selected.Value),
Value(MinuteValue1.Selected.Value),
0
),
TimeZoneOffset(),
Minutes
)
),
scheduledend: If(
IsBlank(DateValue2.SelectedDate),
Blank(),
DateAdd(
DateValue2.SelectedDate + Time(
Value(HourValue2.Selected.Value),
Value(MinuteValue2.Selected.Value),
0
),
TimeZoneOffset(),
Minutes
)
)
}
)
In the above formula we have implemented the “DateAdd” and “TimeZoneOffSet()” function to convert the data and time value into UTC format.
- DataAdd: The DateAddfunction adds a number of units to a date/time value.
- TimeZoneOffSet : The TimeZoneOffsetfunction returns difference between the user’s local time and UTC in minutes.
4. Let’s run the app and set “Start Time” and “End Time” for a record in CRM through PowerApp by selecting in powerApp.
5. Now as shown below the “Start Time” and “End Time” values are updated in CRM in Eastern Time:
Conclusion
PowerApps allows user to handle date and time fields of dynamics 365 according to user time zone.
70% of global 2000 companies apply gamification to improve productivity and returns!
Gamifics365 – Spin the magic of games within Microsoft Dynamics 365 CRM to improve user adoption, enhance productivity, and achieve company goals!