Skip to main content

Notifications

Microsoft Dynamics CRM (Archived)

Want to add a custom field that displays both 12 hours and 24 hours time format option to choose.

Posted on by 15

On prem CRM 2015, I want to add a date and time field on the form customized entity, where a user can/should have an option to choose either 12 hours or 24 hours time format. later based on selection the time on the field should changed. I'm not having user behavioral option, as it's not an updated version.

*This post is locked for comments

  • LeoAlt Profile Picture
    LeoAlt 16,329 on at
    RE: Want to add a custom field that displays both 12 hours and 24 hours time format option to choose.

    Hi Salahuddin,

    Date and time field is controlled by personal settings or system settings, so your requirement could be achieved by changing current user settings: the method I gave out is based on that we can change Current Format to different countries In Set Personal Options dialog, in English(US) format, the time is 12 hour format while in Italian(Italy), it's 24h.

    My core logic is below, 

     

    // localeid: 1033 -> USA, 1040 -> Italy

    var entity = {};

    entity.LocaleId = 1033;

    var userid = Xrm.Page.context.getUserId().replace("{", "").replace("}", "");

    var req = new XMLHttpRequest();

    req.open("POST", Xrm.Page.context.getClientUrl() + "/XRMServices/2011/OrganizationData.svc/UserSettingsSet(guid\'"+ userid +"\')", true);

    req.setRequestHeader("Accept", "application/json");

    req.setRequestHeader("Content-Type", "application/json; charset=utf-8");

    req.setRequestHeader("X-HTTP-Method", "MERGE");

    req.onreadystatechange = function() {

        if (this.readyState === 4) {

            this.onreadystatechange = null;

            if (this.status === 204 || this.status === 1223) {

                // Perform your success action

            } else {

                alert(this.statusText);

            }

        }

    };

    req.send(JSON.stringify(entity));

     

    I send a PATCH Ajax request to update current user format settings.

    You could find supported methods and writable attributes for updating user's settings in this official doc:

    https://docs.microsoft.com/en-us/dynamics365/customer-engagement/developer/entities/usersettings#BKMK_LocaleId

    Note:

    1. I tried to update single time format, but it didn't change time format so I have to update country format directly.
    2. By updating at country level, all format attributes will be changed, you could customize format settings for different countries to meet your business requirement.
    3. I just gave a part of implementation, you could create a web resource with an option lists and a button to execute the update for your form, then refresh page. (Because its a back-end action).

    If you're not familiar with JavaScript and how to work with web resource, i'm glad to give more steps.

    1. Please let me know what "I'm not having user behavioral option" means. 

    Best Regards,

    Leo

  • Suggested answer
    Prashant_ Profile Picture
    Prashant_ 1,040 on at
    RE: Want to add a custom field that displays both 12 hours and 24 hours time format option to choose.

    Following thread might help you

    community.dynamics.com/.../change-the-time-format

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!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,149 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans