Hi,
Can we restrict the user from logging work for previous month. As per the scenario, I am trying to disable the time spent field in the Log Work Screen, if the Date Started is having a value of previous month. I tried behavior but in vain. Here is my script that I am trying to write using a listener:
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.fields.CustomField;
import com.onresolve.jira.groovy.user.FormField
import com.atlassian.jira.issue.worklog.*
import com.atlassian.jira.issue.MutableIssue
CustomField timespentField = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Time Spent")
CustomField startDateField = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Date Started")
def today=new Date().format("yyyy-MM-dd")
//def issue = event.issue as Issue
MutableIssue issue = event.issue as MutableIssue
//def startDateVal = issue.getCustomFieldValue(startDateField) as Date
log.error(issue.getCustomFieldValue(startDateField))
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def change = event?.getChangeLog()?.getRelated("ChildChangeItem").find {it.field == "Date Started"}
log.error("change is "+ change)
if(change){
def startDateVal = issue.getCustomFieldValue(startDateField) as Date
log.error("start date is "+ startDateVal)
def month=startDateVal.format("MM")
def year=startDateVal.format("yyyy")
Calendar cacheCalendar = Calendar.instance
cacheCalendar.set(Calendar.MONTH, (Integer.parseInt(month)+1));
cacheCalendar.set(Calendar.YEAR, Integer.parseInt(year));
def cutoffDate=cacheCalendar.time.format("yyyy-MM-05")
def monthStart=startDateVal.format("yyyy-MM-01")
log.error("Month Start:"+monthStart+"....cutOffDate:"+cutoffDate)
if(monthStart<=today && today<cutoffDate){
timespentField.hide();
issue.timespentField.setVisible(false)
}
else {
getFieldById("log-work-time-logged").setHidden(false)
timespentField.setRequired(false)
}
}
Any help will be highly appreciated.