Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Suggested answer

Set time zone and content settings depending on current user

(0) ShareShare
ReportReport
Posted on by 274

Is there a possibility to set the time zone and content settings in a customer journey depending on the current user? 

Situation : user in Timezone A always use Content Settings A, and user in Timezone B always use Content Settings B. 

We can set only one timezone and content settings in the default marketing settings, so one of the users always need to do a manual change. 

Have anyone an idea?

Regards,

Eline

  • Suggested answer
    cloflyMao Profile Picture
    cloflyMao 25,202 on at
    RE: Set time zone and content settings depending on current user

    Hi Eline,

    It can be done with JavaScript:

    Please run the function at OnLoad event of customer journey form and check whether it works for you.

    The sample code will set the timezone of customer journey to timezone of current user, and set the content settings to "My Content Settings" if timezone of current user is in GMT 8.

    function onLoad(executionContext) {
    
        var formContext = executionContext.getFormContext();
    
        // Get user ID of current user
        var utility = Xrm.Utility
        var userId = utility.getGlobalContext().userSettings.userId;
        userId = userId.replace(/\{|\}/gi, "").toLowerCase();
        
        // Get server URL
        var globalContext = utility.getGlobalContext();
        var serverURL = globalContext.getClientUrl();
    
        // Add your content settings here(There are several regions in same timezone)
        var GMT_Plus_8 = [207, 210, 215, 220, 225, 227, 228];
        var contentSettings_1 = [{ id: "73c8f2d1-b43a-eb11-a813-000d3a80c481", name: "My Content Settings", entityType: "msdyncrm_contentsettings" }];
    
        var req = new XMLHttpRequest();
        req.open("GET", serverURL   "/api/data/v9.0/usersettingscollection?$select=timezonecode&$filter=systemuserid eq "   userId, true);
        req.setRequestHeader("Accept", "application/json");
        req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
        req.setRequestHeader("OData-MaxVersion", "4.0");
        req.setRequestHeader("OData-Version", "4.0");
        req.onreadystatechange = function () {
            if (this.readyState == 4) {
                req.onreadystatechange = null;
                if (this.status == 200) {
                    var result = JSON.parse(this.response);
                    // Get timezone code of current user from response data
                    var userTimezoneCode = result.value[0].timezonecode
                    
                    // Set timezone of customer journey based on current user's timezone
                    formContext.getAttribute("msdyncrm_customerjourneytimezone").setValue(userTimezoneCode);
                    // Set content settings of customer journey based on current user's timezone
                    if (GMT_Plus_8.indexOf(userTimezoneCode) > -1) {
                        formContext.getAttribute("msdyncrm_contentsettingsid").setValue(contentSettings_1);
                    }
                    // Add your own settings here
                } else {
                    var error = JSON.parse(this.response).error;
                    console.log(error.message);
                }
            }
        };
        req.send();
    }

    How does the code work?

    In Dynamics, timezone of specific user is stored in the entity called "UserSettings", e.g: there is a usersetting record for user Clofly:

    --------------------------------------------------

    * systemuserid: aaaa-bbbb

    * timezonecode: 210 (GMT 8 Beijing)

    --------------------------------------------------

    Time zone code of Customer Journey is the same as time zone code of User, we can find code of all timezones in table of following article:

    https://powerobjects.com/crm-101/importing-values-time-zone-fields-dynamics-crm/

    Therefore, once having retrieved timezone code of current user, then we can set timezone of journey to the value.

    For content settings, please check my code, I believe it is easy to extend it with your own settings.

    // Add your content settings here(There are several regions in same timezone)
    var GMT_Plus_8 = [207, 210, 215, 220, 225, 227, 228];
    var contentSettings_1 = [{ id: "73c8f2d1-b43a-eb11-a813-000d3a80c481", name: "My Content Settings", entityType: "msdyncrm_contentsettings" }];

    Regards,

    Clofly

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Tip: Become a User Group leader!

Join the ranks of valued community UG leaders

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,516 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,403 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans