Help with Business Rule - restrict project time cards being submitted beyond resource plan end date

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-04-2023 02:25 AM - edited 07-04-2023 04:33 AM
Hi Community,
We want to restrict time card users to create/update project time card records if the resource plan has ended (regardless if the RP is in Allocated or Completed state). OOTB if the user uses Copy from Previous Time Sheet UI Action they are able to create and submit time cards linked to projects even if their resource plan has ended, which we want to prevent from happening.
We have been advised previously that a Business Rule should do the trick but so far we have been unable to build one and make it work. If you have any other suggestion on how to achieve this, please share.
Thank you.
Paula
----------------------
Had a go at building a BR, however though it works when I try to create a time card from current week, if I try to create a project time card retrospectively (using Copy from Previous Time Sheet) the BR is no longer honoured
(function executeRule(current, previous /*null when async*/ ) {
// check if the category is "project/project task"
if (current.category == 'project_work') {
//get the resource plan end date
var resourcePlanStartDate = new GlideDate(current.resource_plan.start_date);
var resourcePlanEndDate = new GlideDate(current.resource_plan.end_date);
//get the week starts on from the time card
var weekStartsOn = new GlideDate(current.week_starts_on);
//check if the week starts on falls within the resource plan dates
if (weekStartsOn < resourcePlanStartDate || weekStartsOn > resourcePlanEndDate) {
// Display an error message and prevent time card creation
current.setAbortAction(true);
gs.addErrorMessage('You cannot submit project time outside resource plan dates');
}
}
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-04-2023 06:12 AM - edited 07-04-2023 06:12 AM
@PaulaaO Have you tried to replicate your business rule to a script included and return true or false in the UI Action?
Because you said your Bussiness Rule work but the UI Action passes that validation, right?