hi guys,
I need some help on a date time picker validator; We have 2 date time pickers (Maintenance - Start Time, Maintenance - End Time), my only requirement is to validate if selected Maintenance - Start Time and Maintenance - End Time have been booked? If it's booked, then prevent it from creating (a new issue) and display a message ("this time slot is booked"), otherwise, ok to create a new issue.
regards,
Henry
@Henry Lin what does it mean "booked"? What would this condition look like? Let's say we have
So the condition should be
Do I understand it correctly?
hi @Martin Bayer _MoroSystems_ s_r_o__ , pretty closed! This validation checks the date and the time in one project; for example, let's say we have an event scheduled at 8pm - 10pm July 30th (under project X), and someone wants to schedule another event at 9pm of July 30th on create issue screen (of project X), the screen should show an error message ("this time has been booked or it's not available, please selected another time"), and prevent the issue to be created.
we have Scriptrunner in place, but not sure how to validate the date and time. Much appreciate your help!
regards,
Henry
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
hi @Henry Lin I would prepare JQL which will return issues which matches condition you described. So there must not be any existing issue which has Start or End date in range of Start-End of issue to be created (you need to use scripted validator)
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.search.SearchProvider
import com.atlassian.jira.jql.parser.JqlQueryParser
import com.atlassian.jira.web.bean.PagerFilter
def jqlQueryParser = ComponentAccessor.getComponent(JqlQueryParser)
def searchProvider = ComponentAccessor.getComponent(SearchProvider)
def issueManager = ComponentAccessor.getIssueManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def user = ComponentAccessor.getJiraAuthenticationContext().getUser() // edit this query to suit
def dateTimeFormat = "yyyy-MM-dd HH:mm"
def maintenanceStartCF = customFieldManager.getCustomFieldObject(xxxxL)
def maintenanceStartDate = issue.getCustomFieldValue(maintenanceStartCF)
def maintenanceStartString = maintenanceStartDate.format(dateTimeFormat)
def maintenanceEndCF = customFieldManager.getCustomFieldObject(xxxxL)
def maintenanceEndDate = issue.getCustomFieldValue(maintenanceEndCF)
def maintenanceEndString = maintenanceEndDate.format(dateTimeFormat)
def jqlQuery = 'project = X AND ("Maintenance - Start Time">=$maintenanceStartString AND "Maintenance - Start Time"<=$maintenanceEndString OR "Maintenance - End Time">=$maintenanceStartString AND "Maintenance - End Time"<=$maintenanceEndString )'
def query = jqlQueryParser.parseQuery(jqlQuery)
def results = searchProvider.search(query, user, PagerFilter.getUnlimitedFilter()) log.debug("Total issues: ${results.total}")
if(results.total > 0) {
throw new InvalidInputException(maintenanceStartCF.id, "this time has been booked or it's not available, please selected another time")
}
I don't have any server environment to test the script so can you test it?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
hi @Martin Bayer _MoroSystems_ s_r_o__ , appreciate the code! I'll test out the code when i get back from the vacation in a week, and I will let you know how it goes!
regards,
Henry
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Jira Product Discovery Premium is now available! Get more visibility, control, and support to build products at scale.
Learn moreOnline forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.