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 02:38 AM - edited 07-04-2023 02:39 AM
I am not an expert on this.
But the problem you are having probably you can resolve with 2 option
1º
Create an ACL with a group of users depending on a condition to prevent write/update records of that table
2º
Create a condition in the UI action where you check the role or group of the current user

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-04-2023 03:27 AM
Hi @TiagoPinto thanks for replying however I am struggling to see how either of the solutions would work. I need somehow to use the resource plan end date to drive the action of being able to create a project/project task time card type. I did think about updating the UI action or the script include which calls it, however I don't have enough developing experience to know how to achieve this
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-04-2023 03:58 AM - edited 07-04-2023 03:58 AM
Hi @PaulaaO , can you share a ScreenShot of the Copy from Previous Time Sheet UI Action.
The restriction is based on what type of field( choice, date, etc...) ? .

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-04-2023 04:36 AM
If it helps, I've shared the bit from the Script Included called in the UI Action:
canCopyFromPreviousTimesheet: function(userId){
var nonAllowedStates = ['Approved', 'Processed'];
return this._hasSubmitAccess(userId) && (nonAllowedStates.indexOf(this.gr.getValue("state")) == -1);
},