I am needing help with limiting a date field in the mobile agent app.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-22-2024 07:42 AM
I have a requirement to limit a date range via javascript for the Agent mobile application. Please see the code below. I am aiming to limit work_date to not allow any date selected before the previous month and no date after the next month. I am also aiming to configure an error message to go along with the validation. Any help would be much appreciated.
Current Code:
(function WriteBackAction(input) {
//Type appropriate comment here, and begin script below
if ((gs.nil(input.time_worked_hours) && gs.nil(input.time_worked_minutes))
|| input.time_worked_hours > 99 || input.time_worked_minutes > 99 ||
input.time_worked_hours < 0 || input.time_worked_minutes < 0 ||
(input.time_worked_hours == 0 && input.time_worked_minutes == 0)) {
gs.addErrorMessage(gs.getMessage("Invalid time worked entry"));
return;
}
var hour = input.time_worked_hours< 10 ? '0' + input.time_worked_hours : input.time_worked_hours;
var minutes = input.time_worked_minutes < 10 ? '0' + input.time_worked_minutes : input.time_worked_minutes;
var time_worked = new GlideDuration('0 ' + hour + ':' + minutes +':00');
var gr = new GlideRecord("task_time_worked");
gr.initialize();
gr.user = gs.getUserID();
gr.task = input.task_id;
gr.category = input.category;
gr.comments = input.comments;
if (input.rate_type) {
gr.rate_type = input.rate_type;
}
gr.work_date = input.work_date;
gr.time_worked = time_worked;
gr.insert();
})(input);