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