...
Code Block |
---|
import com.deniz.jira.worklog.scripting.WorklogPreEntryParameters;
worklogPreEntryParameters.jsScript = '''
setTimeout(function () {
AJS.$("#add-worklog-dialog-timesheet").width("700px");
}, 10);
'''
return worklogPreEntryParameters; |
Resize of Worklog Dialog
Set an error message below the issue, if value of a field is not provided. In the below example, we are checking the value of “STAR Reference” field and if it is not provided, we are showing an error message just below the issue.
Code Block |
---|
|
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.customfields.option.Option;
import com.deniz.jira.worklog.services.attr.AttrTypeService;
import com.atlassian.jira.component.*;
import com.atlassian.jira.issue.*;
import org.slf4j.*;
import com.deniz.jira.worklog.*;
import com.atlassian.jira.security.JiraAuthenticationContext;
//please enable logging for package "com.deniz.jira.worklog.scripting" from Administration/System/Logging and Profiling
Logger log = LoggerFactory.getLogger(com.deniz.jira.worklog.scripting.ScriptingService.class);
def issueManager = ComponentAccessor.getComponent(IssueManager.class);
def referenceFieldObject = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("STAR Reference");
def error = null;
def issue = issueManager.getIssueObject(worklogPreEntryParameters.issueKey);
log.debug("issue:{}", issue);
if(referenceFieldObject!=null){
def referenceFieldValue = (Option) issue.getCustomFieldValue(referenceFieldObject);
log.debug("referenceFieldValue:{}.", referenceFieldValue );
// Check if reference is absent and not in exception list
if (referenceFieldValue == null || referenceFieldValue == ""){
error = "No logging possible: No STAR Reference selected in this issue.";
}
// Check if reference is disabled
if ((referenceFieldValue != null) && (referenceFieldValue.getDisabled()==true)){
error = "No logging possible: The STAR Reference selected in this issue has been disabled";
}
}
if (error != null) {
log.debug("setting error:{}", error);
worklogPreEntryParameters.jsScript = """
setTimeout(function() {
AJS.\$("<p id='star-error' class='error'>${error}</p>").appendTo("#log-work-issue-picker-single-select");
}, 100);
""";
} else {
worklogPreEntryParameters.jsScript = """
setTimeout(function() {
AJS.\$("#star-error").remove();
}, 100);
""";
}
return worklogPreEntryParameters; |