Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics 365 | Integration, Dataverse...
Suggested answer

All day event breaks custom Javascript start and end date

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
  • Suggested answer
    Henry J. Profile Picture
    Henry J. 5,237 on at
    RE: All day event breaks custom Javascript start and end date

    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

  • Suggested answer
    Johao Larios Profile Picture
    Johao Larios 1,795 on at
    RE: All day event breaks custom Javascript start and end date

    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

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans