web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics 365 | Integration, Dataverse...
Suggested Answer

All day event breaks custom Javascript start and end date

(0) ShareShare
ReportReport
Posted on by 10
When I am trying to modify the appointment all day start and end times (from 12 - 12 to 9 -5) and I have the below function which used to do just that on the legacy form, it does all sorts of strange things. 
First some background, the function is registered on onChange of the alldayevent checkbox and checks for whether said checkbox returns true. Anyway, when trying to set recurrence this does not work. It is something to do with the way that datetimes now work, I think. I could use any sort of guidance with this as I have nearly had it with this. The client requirement is the reason for the modification of start and end times to 9 - 5. 
The expected behavior is that when the alldayevent checkbox is selected, even though default mscrm behavior is to hide the start and end time fields on the form, it still ought to change the values themselves. However, when selecting the recurrence option from the ribbon, the start and end times are the first two fields on the popup form. They should, given that the below code runs onChange of the checkbox, show 9:00 am to 5:00pm. 
Important clue/quirk. If you deselect the alldayevent checkbox, while still on the main form, the start and end times DO show 9 -5. But, even so, the recurrence form does not. *shrugs*
The below script was borrowed and copypasta style (likely from this forum), and I don't entirely follow how it is doing. But, given that it did work in the legacy client, it does suggest that this is due to something specific to the new interface.
function SetAllDayEventTimes() {
    //if (xrmPage.ui.getFormType() == 1 && Xrm.Page.getAttribute("isalldayevent").getValue() == true )
    if (xrmPage.getAttribute("isalldayevent").getValue() == true) {
        var duration = xrmPage.getAttribute('scheduleddurationminutes');
        duration.setValue(0);
        duration.setValue(60 * 8);
        var start = xrmPage.getAttribute('scheduledstart');
        var end = xrmPage.getAttribute('scheduledend');

        var newStart = new Date(start.getValue());
        var startHour = newStart.getHours();
        newStart.setHours(9, 0, 0);
        start.setValue(newStart);

        var newEnd = new Date(start.getValue());
        var endHour = newEnd.getHours();
        newEnd.setHours(endHour   8);
        end.setValue(newEnd);

        xrmPage.getAttribute("scheduledstart").setValue(newStart);
        xrmPage.getAttribute("scheduledend").setValue(newEnd);
    }
}
 
Thanks in advance for any suggestions
I have the same question (0)
  • Suggested answer
    Johao Larios Profile Picture
    1,795 on at

    Hello there,

    My first recommendation is work to change the code to work with the execution context: docs.microsoft.com/.../getformcontext which is the new way to interact with the Forms and attributtes.

    docs.microsoft.com/.../behavior-format-date-time-field

  • Suggested answer
    Henry J. Profile Picture
    5,237 on at

    Hello,

    "All Day Event" appointments in Dynamics 365 have the same behavior as "All day" meetings in Outlook. It sets the start time and end time at 00:00, so that the meeting lasts all 24 hours of the day.

    If you're looking at helping users creating 9 to 5 meetings, then I advise to create a distinct "Full Business Day'" checkbox for this, that doesn't hide start time and end time but rather sets default values (9am and 5pm) for them.
    Otherwise, your logic tries to twist out-of-the-box behavior and conflicts with default activities logic. 

    Henry

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the June Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Microsoft Dynamics 365 | Integration, Dataverse, and general topics

#1
11manish Profile Picture

11manish 107

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 59 Super User 2026 Season 1

#3
sannavajjala87 Profile Picture

sannavajjala87 29

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans