- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-31-2023 11:42 PM
Dear Team,
In Employee Center I am able to add a delegate, start date, end date and duties, currently start date and end date are whatever we selected through the calendar as the duration of delegation but I want to Limit the Duration of Delegation to no longer/more than 60days, if the user tries to select an end date to me more than 60days then it throws an error message 'Delegation duration should not be more than 60days' and clears the End Date field value (date).
Requesting help to get this acheived.
Thank You
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2023 01:02 AM - edited 08-01-2023 04:04 AM
@rishabh31 Yes you can achieve this 2 ways.
Client vs Server.
via onchange client script you can check difference between 2 dates abort action if it is more than 60days( drawback is on list view won't work)
Via before business rule will be best solution as it stop from list form or any other source.
writr]e a before business rule in delegation table
on insert and update
start date or end date changes
in script:
var start = new GlideDateTime(current.starts);
var end = new GlideDateTime(current.ends);
var diff = GlideDateTime.subtract(start, end);
var days = diff.getRoundedDayPart();
if(days>60){
gs.addErrorMessage("Not allowed to delegate user for more than 60 days");
current.setAbortAction(true);
}
Bharath Chintala
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2023 01:02 AM - edited 08-01-2023 04:04 AM
@rishabh31 Yes you can achieve this 2 ways.
Client vs Server.
via onchange client script you can check difference between 2 dates abort action if it is more than 60days( drawback is on list view won't work)
Via before business rule will be best solution as it stop from list form or any other source.
writr]e a before business rule in delegation table
on insert and update
start date or end date changes
in script:
var start = new GlideDateTime(current.starts);
var end = new GlideDateTime(current.ends);
var diff = GlideDateTime.subtract(start, end);
var days = diff.getRoundedDayPart();
if(days>60){
gs.addErrorMessage("Not allowed to delegate user for more than 60 days");
current.setAbortAction(true);
}
Bharath Chintala
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2023 04:13 AM
Thank You @BharathChintala Sir,
This is working fine. Per your help tested this by applying logs and checking table 'syslog' after each save or trying to save a new 'sys_granular_delegate' record.
(function executeRule(current, previous /*null when async*/ ) {
var start = new GlideDateTime(current.starts);
var end = new GlideDateTime(current.ends);
var diff = GlideDateTime.subtract(start, end);
var days = diff.getRoundedDayPart();
gs.info("Rishabh Starts " + start);
gs.info("Rishabh Ends " + end);
gs.info("Rishabh diffsec " + diff);
gs.info("Rishabh diffday " + days);
if (days > 60) {
gs.addErrorMessage(gs.getMessage("Not allowed to delegate user for more than 60 days"));
current.setAbortAction(true);
}
})(current, previous);
It gives logs data as (correctly subtracting the No. of days i.e., 155)
Once again thank you so much, marked your response correct and helpful.