I want to implement a function with script runner: to automatically replenish Duedate by "Severity" when creating an issue
Severity Duedate
S Create Date + 2D
A Create Date + 5D
B Create Date + 10D
Hi @dengfuwen
As far as I understand, you are using Script Runner to update the issue's due date based on the value of a custom field. We need more information but here is the code that would help you as a start. The code would change based on the custom field type (text, dropdown, etc) and where you would use it (post function, listener, etc).
Anyway, I have to say that I haven't tested the code, but as I mentioned it might help you with your needs. Let me know if you need further assistance.
import com.atlassian.jira.component.ComponentAccessorimport com.atlassian.jira.issue.MutableIssueimport com.atlassian.jira.event.type.EventDispatchOptiondef mutableIssue = issue as MutableIssuedef customFieldManager = ComponentAccessor.customFieldManagerdef issueManager = ComponentAccessor.issueManagerdef user = ComponentAccessor.jiraAuthenticationContext.loggedInUserdef SEVERITY_CUSTOMFIELD_ID = xxxxx // the long id value of the custom fielddef dateToSet = issue.createddef severityCustomField = customFieldManager.getCustomFieldObject(SEVERITY_CUSTOMFIELD_ID)def severityValue = issue.getCustomFieldValue(severityCustomField)if (severityValue == "S") {dateToSet = dateToSet + 2} else if (severityValue == "A") {dateToSet = dateToSet + 5} else if (severityValue == "B") {dateToSet = dateToSet + 10}mutableIssue.setDueDate(dateToSet)issueManager.updateIssue(user, mutableIssue, EventDispatchOption.ISSUE_UPDATED, false)
What scripting or automation apps do you have? (You'll need one to do this)
Hi I tried to implement functionality with the code you provided but found error in last line of code error log below please help solve Thanks
log :2022-04-06 10:55:00,269 ERROR [workflow.AbstractScriptWorkflowFunction]: Workflow script has failed for user 'fuwen.deng'. View here: https://jira.tclking.com/secure/admin/workflows/ViewWorkflowTransition.jspa?workflowMode=live&workflowName=Eagle-Lab+Bug+v4&descriptorTab=postfunctions&workflowTransition=1&highlight=1 groovy.lang.MissingPropertyException: No such property: EventDispatchOption for class: Script583 at Script583.run(Script583.groovy:25)
Agh! I forgot to add the import statement.
import com.atlassian.jira.event.type.EventDispatchOption
Also, I noticed that I have used createdDate in the last line, it should be dateToSet.
I've updated the above code accordingly.
Hi
I changed the latest code for your generation and I still reported an error: issue = null
Please run the code in your jira environment and answer me again?I hope to do things right once can improve our efficiency.
Thank you!!
Logs:
2022-04-07 10:38:36,029 ERROR [workflow.AbstractScriptWorkflowFunction]: Workflow script has failed for user 'fuwen.deng'. View here: https://jira.tclking.com/secure/admin/workflows/ViewWorkflowTransition.jspa?workflowMode=live&workflowName=Eagle-Lab+Bug+v4&descriptorTab=postfunctions&workflowTransition=1&highlight=1com.google.common.util.concurrent.UncheckedExecutionException: java.lang.NullPointerException: null value in entry: issue=nullat com.google.common.cache.LocalCache$Segment.get(LocalCache.java:2050)at com.google.common.cache.LocalCache.get(LocalCache.java:3952)at com.google.common.cache.LocalCache$LocalManualCache.get(LocalCache.java:4871)at com.atlassian.jira.issue.customfields.persistence.EagerLoadingOfBizCustomFieldPersister.getValuesForIssueId(EagerLoadingOfBizCustomFieldPersister.java:114)at com.atlassian.jira.issue.customfields.persistence.EagerLoadingOfBizCustomFieldPersister.getValuesForTypeAndParent(EagerLoadingOfBizCustomFieldPersister.java:98)at com.atlassian.jira.issue.customfields.persistence.OfBizCustomFieldValuePersister.updateValues(OfBizCustomFieldValuePersister.java:158)at com.atlassian.jira.issue.customfields.persistence.EagerLoadingOfBizCustomFieldPersister.updateValues(EagerLoadingOfBizCustomFieldPersister.java:67)at com.atlassian.jira.issue.customfields.persistence.OfBizCustomFieldValuePersister.createValues(OfBizCustomFieldValuePersister.java:113)at com.atlassian.jira.issue.customfields.persistence.EagerLoadingOfBizCustomFieldPersister.createValues(EagerLoadingOfBizCustomFieldPersister.java:55)at com.atlassian.jira.issue.customfields.persistence.OfBizCustomFieldValuePersister.createValues(OfBizCustomFieldValuePersister.java:105)at com.atlassian.jira.issue.customfields.persistence.EagerLoadingOfBizCustomFieldPersister.createValues(EagerLoadingOfBizCustomFieldPersister.java:49)at com.atlassian.jira.issue.customfields.impl.AbstractSingleFieldType.createValue(AbstractSingleFieldType.java:144)at com.atlassian.jira.issue.fields.ImmutableCustomField.createValue(ImmutableCustomField.java:701)at com.atlassian.jira.issue.fields.ImmutableCustomField.updateValue(ImmutableCustomField.java:414)at com.atlassian.jira.issue.fields.ImmutableCustomField.updateValue(ImmutableCustomField.java:400)at com.atlassian.jira.issue.managers.DefaultIssueManager.updateFieldValues(DefaultIssueManager.java:716)at com.atlassian.jira.issue.managers.DefaultIssueManager.updateIssue(DefaultIssueManager.java:667)at com.atlassian.jira.issue.managers.DefaultIssueManager.updateIssue(DefaultIssueManager.java:653)at com.atlassian.jira.issue.managers.RequestCachingIssueManager.updateIssue(RequestCachingIssueManager.java:217)at com.atlassian.jira.issue.IssueManager$updateIssue$22.call(Unknown Source)at Script670.run(Script670.groovy:25)Caused by: java.lang.NullPointerException: null value in entry: issue=nullat com.google.common.collect.CollectPreconditions.checkEntryNotNull(CollectPreconditions.java:32)at com.google.common.collect.SingletonImmutableBiMap.<init>(SingletonImmutableBiMap.java:42)at com.google.common.collect.ImmutableBiMap.of(ImmutableBiMap.java:72)at com.google.common.collect.ImmutableMap.of(ImmutableMap.java:124)at com.atlassian.jira.issue.customfields.persistence.EagerLoadingOfBizCustomFieldPersister.lambda$getValuesForIssueId$1(EagerLoadingOfBizCustomFieldPersister.java:115)at com.google.common.cache.LocalCache$LocalManualCache$1.load(LocalCache.java:4876)at com.google.common.cache.LocalCache$LoadingValueReference.loadFuture(LocalCache.java:3528)at com.google.common.cache.LocalCache$Segment.loadSync(LocalCache.java:2277)at com.google.common.cache.LocalCache$Segment.lockedGetOrLoad(LocalCache.java:2154)at com.google.common.cache.LocalCache$Segment.get(LocalCache.java:2044)... 20 more
Hello, do you have any good way to help me?
It looks like you're new here. Sign in or register to get started.