Example: Limit past dates for current work logs
We will explain how to implement a validation for preventing work logs with a beginning date before a time limit in the past.
In particular, we will explain how to avoid work logs where the associated date is earlier than 10 days in the past, i.e. If we are on march 25th, today we only allow work logs with march 15th or later as a beginning date.
Enforce work logs through transitions
First we need to enforce users to log all the work using transitions in our workflows, instead of using "Log Work" operation at the issue screen. To do it we will:
- Remove "Log Work" option from operation menu:
Administration > Add-ons > Manage add-ons > Filter by "System" > Issue Operations Plugin > Disable module "View Issue Ops Bar Work Link"
- Create a screen with only one field: "Log Work". You can call it "Work Log in Transition".
- Add reflexive transitions called "Log Work" in the statuses of our workflow where we want users to be allowed to log work, and we associate them the screen "Work Log in Transition", created in the previous step. These transitions have the same status as origin and destination, leaving the issue in the same status, but showing the user a screen where they will be able to log work.
Typically you will add this transition to "In Progress" status, but you can add this transition to all statuses easily using a global reflexive transition.
You can use conditions or validations to limit who can execute these transition, and thus who can log work.
Now we only need to insert Boolean Validator with math, date-time or text-string terms in "Log Work" transitions using the following configuration:
Boolean expression used is: datePart({00057}, LOCAL) - datePart({00166}, LOCAL) <= 10 * {DAY}
Note that:
- {00057} is code for numeric value of virtual field "Current date and time"
- {00166} is code for numeric value of virtual field "Date and time of work logged in transition"
Once all the post-functions have been inserted, transition "Log Work" will look like this:
Other variation of the usage example
If you want to limit valid work logs to dates within current week you should use any of the following validations:
Weeks begin on Sundays
dayOfTheWeek({00057}, LOCAL) <= (datePart({00166}, LOCAL) - datePart({00057}, LOCAL)) / {DAY} AND (datePart({00166}, LOCAL) - datePart({00057}, LOCAL)) / {DAY} <= 7 - dayOfTheWeek({00057}, LOCAL)
Weeks begin on Mondays
dayOfTheWeek({00057}, LOCAL) != {SUNDAY} ? (2 - dayOfTheWeek({00057}, LOCAL) <= (datePart({00166}, LOCAL) - datePart({00057}, LOCAL)) / {DAY} AND (datePart({00166}, LOCAL) - datePart({00057}, LOCAL)) / {DAY} <= 8 - dayOfTheWeek({00057}, LOCAL)) : (-6 <= (datePart({00166}, LOCAL) - datePart({00057}, LOCAL)) / {DAY} AND (datePart({00166}, LOCAL) - datePart({00057}, LOCAL)) / {DAY} <= 0)
Other examples of that function
- Block a transition until all sub-tasks have certains fields populated
- Block an epic's transition depending on linked issues status and due date
- Block or hide a transition for an issue depending on its issue links
- Block or unblock a transition after an issue rested a specific time in a status
- Block transition until all sub-tasks are in a specific status category
- Close parent issue when all sub-tasks are closed
- Enforce a field (Select List) to be set when another field (Radio Button) has a certain value (works with any kind of field type)
- Ensure that all issues linked with a certain issue link type have "Due Date" field set
- If field A is populated then, field B must also be populated
- Limit issue creation per role and issue type
- Limit the number of hours a user can log per day
- Limit valid dates for work logs
- Make "Time Spent" field required when there is no time logged in the issue
- Make a custom field mandatory when priority is "Critical" or "Blocker" and issue type is "Incident"
- Make attachment mandatory depending on the value of certain custom field
- Make different fields mandatory depending on the value of a Select List custom field
- Make linked issues, sub-tasks and JQL selected issues progress through its workflows
- Make parent issue progress through its workflow
- Prevent issue creation if another issue with same field value already exists
- Reject duplicated file names in attachments
- Require at least one sub-task in status "Resolved" or "Closed" when "Testing required" is selected in Check-Box custom field
- Require issue link when resolving as duplicate
- Restrict parent issue from closing if it has sub-tasks that were created during a given parent issue status
- Restrict sub-task type creation depending on parent issue status
- Restrict sub-task type creation depending on parent issue type
- Set a condition in a global transition which only applies in a certain status
- Validate a custom field "Story Points" has been given a value in Fibonacci sequence
- Validate compatible values selection among dependent custom fields
- Validate only issue links created in transition screen
- Validate that multi-user picker custom field A does not contain any user in multi-user picker custom field B
- Validation and condition based on time expressions
- Validation based on the value of a date type project property
- Validation on issue attachments
- Validation on MIME types of issue attachments
- Validation on sibling sub-tasks depending on issue type and status
- Validation on the value of a Cascading Select field