- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-12-2024 08:04 AM
- Dear Team ,
Catalog form I have start and enda date time fields all time of validation completed like time should between 8 to 18 only etc... And working fine. One problem I am facing in Ritm for example I have impersonate with US timezone user and selected start and end date like this 15 Jan 2024 time is 14 hours and then submitted the form RITM got generated.
Step 2 . In my timezone is CET ... End important and login with my timezone and seeing the Ritm it's showing 20 hours .. I need time between 8 to 18 only always user should allow to select and in Ritm I want to see in catalog whatever time selected same I want ... How solve this please help me . anyone
In script include I have done all validations like 8 to 18 hr between only should select otherwise through error etc...
Besed on users timezone only it's showing the time in RITm
If any more details need for solving issue please let me know
Thankyou
Bandi
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-12-2024 12:41 PM
Hello @pavana3 ,
Please give a try to the script below and let me know how it works for you.
Client Script:
if (newValue !== '') {
var date_time = g_form.getValue("FDD_ImplementStartDateTime").split(" ");
var date = date_time[0];
var time = date_time[1];
g_form.setValue("FDD_ImplementStartDate", date);
g_form.setValue("FND_ImplementStartTime", time);
var gAjax = new GlideAjax('BICMDBCatalogItemsUtils');
gAjax.addParam('sysparm_name', 'validateImplementationStartDateTime');
gAjax.addParam('sysparm_impl_startDate', newValue);
gAjax.addParam('sysparm_leadTime', g_form.getValue('FND_Leadtime'));
gAjax.addParam('sysparm_used_for', g_form.getValue('used_for'));
gAjax.addParam('sysparm_agreedHours', g_form.getValue('implementation_outside_agreed_service_hours'));
// Add time zone information to the GlideAjax call
var userTimeZone = g_form.getUser().getTimeZoneName();
gAjax.addParam('sysparm_userTimeZone', userTimeZone);
gAjax.getXML(validateDate);
}
Script Include:
validateImplementationStartDateTime: function() {
var correctTime = '';
var dateTime = this.getParameter('syparm_impl_startDate');
var leadTime = this.getParameter('sysparm_leadTime');
var usedFor = this.getParameter('sysparm_used_for');
var agreedhours = this.getParameter('sysparm_agreedHours');
var userTimeZone = this.getParameter('sysparm_userTimeZone');
// Use GlideDateTime to handle time zone conversions
var selectedDateTime = new GlideDateTime(dateTime);
selectedDateTime.setTZ(userTimeZone);
if (usedFor !== 'Production' && agreedhours !== 'true') {
correctTime = this.validateTime(selectedDateTime);
} else {
var gdt = new GlideDateTime();
gdt.addDaysLocalTime(leadTime);
gdt.addSeconds(3600);
if (selectedDateTime.after(gdt)) {
return 'true';
} else {
return 'Selected date has to be greater than Now + lead time + 1 hour';
}
}
if (correctTime === 'true') {
var gt = new GlideDateTime();
gt.addDaysLocalTime(leadTime);
gt.addSeconds(3600);
if (selectedDateTime.after(gt)) {
return 'true';
} else {
return 'Selected date has to be greater than Now + lead time + 1 hour';
}
} else {
return "The time should be between 08:00 - 18:00 and the day should be in Weekdays";
}
},
validateTime: function(dateTime) {
// Your existing time validation logic goes here
// Ensure that the time is between 08:00 - 18:00 and the day is a weekday
// Return 'true' if the time is valid, otherwise return an error message
}
Let me know your views on this and Mark ✅Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.
Thanks,
Aniket
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-12-2024 08:33 AM
Start / End Time is at 20:00:00 CET which shouldn't be possible considering this is a QA system and the checkbox for implementation outside agreed service hours is NOT checked.
The problem must be that the requestor is in the US timezone and when he requested it, he entered 14:00:00.
But the validation "08:00-18:00" must happen against CET timestamps
Code is : in client script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-12-2024 12:41 PM
Hello @pavana3 ,
Please give a try to the script below and let me know how it works for you.
Client Script:
if (newValue !== '') {
var date_time = g_form.getValue("FDD_ImplementStartDateTime").split(" ");
var date = date_time[0];
var time = date_time[1];
g_form.setValue("FDD_ImplementStartDate", date);
g_form.setValue("FND_ImplementStartTime", time);
var gAjax = new GlideAjax('BICMDBCatalogItemsUtils');
gAjax.addParam('sysparm_name', 'validateImplementationStartDateTime');
gAjax.addParam('sysparm_impl_startDate', newValue);
gAjax.addParam('sysparm_leadTime', g_form.getValue('FND_Leadtime'));
gAjax.addParam('sysparm_used_for', g_form.getValue('used_for'));
gAjax.addParam('sysparm_agreedHours', g_form.getValue('implementation_outside_agreed_service_hours'));
// Add time zone information to the GlideAjax call
var userTimeZone = g_form.getUser().getTimeZoneName();
gAjax.addParam('sysparm_userTimeZone', userTimeZone);
gAjax.getXML(validateDate);
}
Script Include:
validateImplementationStartDateTime: function() {
var correctTime = '';
var dateTime = this.getParameter('syparm_impl_startDate');
var leadTime = this.getParameter('sysparm_leadTime');
var usedFor = this.getParameter('sysparm_used_for');
var agreedhours = this.getParameter('sysparm_agreedHours');
var userTimeZone = this.getParameter('sysparm_userTimeZone');
// Use GlideDateTime to handle time zone conversions
var selectedDateTime = new GlideDateTime(dateTime);
selectedDateTime.setTZ(userTimeZone);
if (usedFor !== 'Production' && agreedhours !== 'true') {
correctTime = this.validateTime(selectedDateTime);
} else {
var gdt = new GlideDateTime();
gdt.addDaysLocalTime(leadTime);
gdt.addSeconds(3600);
if (selectedDateTime.after(gdt)) {
return 'true';
} else {
return 'Selected date has to be greater than Now + lead time + 1 hour';
}
}
if (correctTime === 'true') {
var gt = new GlideDateTime();
gt.addDaysLocalTime(leadTime);
gt.addSeconds(3600);
if (selectedDateTime.after(gt)) {
return 'true';
} else {
return 'Selected date has to be greater than Now + lead time + 1 hour';
}
} else {
return "The time should be between 08:00 - 18:00 and the day should be in Weekdays";
}
},
validateTime: function(dateTime) {
// Your existing time validation logic goes here
// Ensure that the time is between 08:00 - 18:00 and the day is a weekday
// Return 'true' if the time is valid, otherwise return an error message
}
Let me know your views on this and Mark ✅Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.
Thanks,
Aniket
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-03-2024 06:08 AM
Of course this check can be easily circumvented by any user just by temporarily changing the preferred Time zone on its profile.
The proper solution would be to check the dates against a Schedule that can be associated with a user without the possibility for a user to influence that - like the time zone of the user's location or company or the time zone of the implementation location - depending on business requirements.
In that case a user based in US, or implementing something is US could only select proper dates and times for US, no matter from where with what time zone selection the user submits the request.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-17-2024 11:29 AM
Hello @pavana3 ,
I wanted to check in regarding the response I provided. If my suggestions were beneficial in addressing your query or helped in resolving your issue, would you mind marking it as helpful, accepting the solution, and closing the thread? Your acknowledgment not only shows appreciation for the assistance but also assists future readers who might come across a similar problem.
Thank you for your consideration!
Best regards,
Aniket.