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

PaulaaO
Mega Sage

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);

 

5 REPLIES 5

TiagoPinto
Tera Contributor

I am not an expert on this.
But the problem you are having probably you can resolve with 2 option

Create an ACL with a group of users depending on a condition to prevent write/update records of that table

Create a condition in the UI action where you check the role or group of the current user

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

TiagoPinto
Tera Contributor

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...) ? .

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);
	},