client script to change date and time value of field b based on the users time zone while form load
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-28-2024 10:53 PM - edited 04-29-2024 01:56 AM
Hi,
I have a ask in which when fieldA is changed, fieldB (dateAndTime field) should populate the current date and time based on users time zone. Also when any other user opens the form the fieldB should be in the current users time zone, if there is no time zone for the user the fieldB value should be in GMT. This is in scopped application.
below is the onchange client script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-28-2024 11:23 PM
Hi @BALAJI K R ,
Here is the fix: try
function onChangeFieldA(control, oldValue, newValue, isLoading) {
if (isLoading || newValue === '') {
return;
}
var userTimeZone = g_user.getUser().getPreference('timezone');
var timeZoneOffset = userTimeZone ? getUserTimeZoneOffset(userTimeZone) : 0;
var currentDate = new Date(new Date().getTime() + (timeZoneOffset * 60000));
g_form.setValue('fieldB', formatDate(currentDate, g_user_date_time_format));
}
function getUserTimeZoneOffset(timezone) {
var timeZoneOffset = timezone.split('GMT')[1];
var sign = timeZoneOffset[0] === '+' ? 1 : -1;
var hours = parseInt(timeZoneOffset.slice(1, 3));
var minutes = parseInt(timeZoneOffset.slice(3, 5));
return sign * (hours * 60 + minutes);
}
function formatDate(date, format) {
return date;
}
☑️ Please mark responses as HELPFUL or ACCEPT SOLUTION to assist future users in finding the right solution....
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-29-2024 01:55 AM - edited 04-29-2024 01:56 AM
I'm getting this error, also this is in Scoped application
below is the script