Hello Community.
Any help would be appreciated.
I have a custom field drop down list, that details three different sites,
Based on the selection of that site I have two custom fields that need to be updated with the correct people assigned to that site.
Both fields are multiple users.
if drop down siteA
then
field 1, user1a and user2a
field 2, user3a
if siteb
then
field1, user1b and user2b
field2, user3b
if siteC
field1, user1c, user2c
field2 user3c
I have scriptrunner, Ive tried a couple of existing scripts but all of them do not work, so im at a loss. Rather than muddy the water, if anyone can help me I would be greatly appreciated.
Running 8.5.4
Scriptrunner 6.17
Hi @Jeremy Cejka ,
it is not clear to me, when this automation should happen. Is it during issue creation or other transition or ... ? Something like your user just created/transitioned some issue and based on the siteA value, which is mandatory, the other fields should be changed...
Thank you for the clarification.
Sorry for not including this, At time of creation. This selection would occur on the create issue screen. And would be a post function trigger.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I started with this, not sure if its right. I kind of took pieces of scripts that kind of matched what i was trying to do.
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.issue.customfields.option.LazyLoadedOption;
import com.atlassian.jira.user.util.UserManager;
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def siteField = customFieldManager.getCustomFieldObject("customfield_14203")
def securityField = customFieldManager.getCustomFieldObject("customfield_14308")
def opsField = customFieldManager.getCustomFieldObject("customfield_14303")
def siteFieldValue = ((LazyLoadedOption)siteField).getValue()
def security = [] as List
def ops = [] as List
if (siteFieldValue == "ALX")
{
security << ComponentAccessor.getUserManager().getUserByKey("user1a")
security << ComponentAccessor.getUserManager().getUserByKey("user2a")
ops << ComponentAccessor.getUserManager().getUserByKey("user3a")
log.debug "ALX"
}
if (siteFieldValue == "MLB")
{
security << ComponentAccessor.getUserManager().getUserByKey("user1b")
security << ComponentAccessor.getUserManager().getUserByKey("user2b")
ops << ComponentAccessor.getUserManager().getUserByKey("user3b")
log.debug "MLB"
}
if (siteFieldValue == "SATX")
{
security << ComponentAccessor.getUserManager().getUserByKey("user1c")
ops << ComponentAccessor.getUserManager().getUserByKey("user2c")
log.debug "SATX"
}
if (siteFieldValue == "Remote")
{
log.debug "Remote"
}
security = security.unique()
securityField.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(securityField), security), new DefaultIssueChangeHolder())
ops = ops.unique()
opsField.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(opsField), ops), new DefaultIssueChangeHolder())
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Jeremy Cejka ,
please try something like this. There's some configuration, which needs to be set up. First of all - option ids for your site custom field. I've used ids instead of names, because it is more safer (ids don't change). Then also keys for your users. I didn't test it much and there are some cases, which should be also handled (like if site custom field is empty etc), but in general I believe it should work.
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.customfields.option.Option
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.user.util.UserManager
Long CUSTOM_FIELD_ID_SITE = 14203
Long CUSTOM_FIELD_ID_SECURITY = 14308
Long CUSTOM_FIELD_ID_OPS = 14303
Long CUSTOM_FIELD_SITE_OPTION_ID_ALX = 11111
Long CUSTOM_FIELD_SITE_OPTION_ID_MLB = 22222
Long CUSTOM_FIELD_SITE_OPTION_ID_SATX = 33333
Long CUSTOM_FIELD_SITE_OPTION_ID_REMOTE = 44444
String USER_KEY_1A = "JIRAUSER11111"
String USER_KEY_1B = "JIRAUSER22222"
String USER_KEY_1C = "JIRAUSER33333"
String USER_KEY_2A = "JIRAUSER44444"
String USER_KEY_2B = "JIRAUSER55555"
String USER_KEY_2C = "JIRAUSER66666"
String USER_KEY_3A = "JIRAUSER77777"
String USER_KEY_3B = "JIRAUSER88888"
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()
UserManager userManager = ComponentAccessor.getUserManager()
CustomField siteField = customFieldManager.getCustomFieldObject(CUSTOM_FIELD_ID_SITE)
CustomField securityField = customFieldManager.getCustomFieldObject(CUSTOM_FIELD_ID_SECURITY)
CustomField opsField = customFieldManager.getCustomFieldObject(CUSTOM_FIELD_ID_OPS)
Option siteFieldValue = issue.getCustomFieldValue(siteField) as Option
Long siteFieldOptionId = siteFieldValue.getOptionId()
List<ApplicationUser> securityUsers = []
List<ApplicationUser> opsUsers = []
switch (siteFieldOptionId) {
case CUSTOM_FIELD_SITE_OPTION_ID_ALX:
securityUsers << userManager.getUserByKey(USER_KEY_1A)
securityUsers << userManager.getUserByKey(USER_KEY_2A)
opsUsers.add(userManager.getUserByKey(USER_KEY_3A))
break
case CUSTOM_FIELD_SITE_OPTION_ID_MLB:
securityUsers << userManager.getUserByKey(USER_KEY_1B)
securityUsers << userManager.getUserByKey(USER_KEY_2B)
opsUsers << userManager.getUserByKey(USER_KEY_3B)
break
case CUSTOM_FIELD_SITE_OPTION_ID_SATX:
securityUsers << userManager.getUserByKey(USER_KEY_1C)
opsUsers << userManager.getUserByKey(USER_KEY_2C)
break
case CUSTOM_FIELD_SITE_OPTION_ID_REMOTE:
// TODO ?
break
}
if (securityUsers.size() > 0) {
DefaultIssueChangeHolder changeHolder = new DefaultIssueChangeHolder()
List<ApplicationUser> securityFieldValue = issue.getCustomFieldValue(securityField) as List<ApplicationUser>
securityField.updateValue(null, issue, new ModifiedValue(securityFieldValue, securityUsers), changeHolder)
}
if (opsUsers.size() > 0) {
DefaultIssueChangeHolder changeHolder = new DefaultIssueChangeHolder()
List<ApplicationUser> opsFieldValue = issue.getCustomFieldValue(opsField) as List<ApplicationUser>
opsField.updateValue(null, issue, new ModifiedValue(opsFieldValue, opsUsers), changeHolder)
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
ok thanks, ill plug it in and report.
Thank you again for assistance.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
For
Long CUSTOM_FIELD_SITE_OPTION_ID_ALX = 11111
I assume that is the supposed to be the backend value matched to the default string option correlating to ALX as a value?
In my example, you pull it from the url pattern when editing the particular value set under default value for the custom_field
https://.../jira/secure/admin/EditCustomFieldOptions!edit.jspa?fieldConfigId=15803&atl_token=BJPH-1N25-G6DR-L9SF_3bdfcd18ebf3ca6ff4344ff3fc6af0a3b37b8d54_lin&selectedValue=12700
selectedValue ~ CUSTOM_FIELD_SITE_OPTION_ID_ALX
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Jeremy Cejka yes, exactly... I'm sorry I wasn't clear enough
Long CUSTOM_FIELD_SITE_OPTION_ID_ALX = 12700
Probably the next option will have id 12701, because you've created it immediately after the first one...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Good morning,
I found this the other day and thought it might be a typo, the syntax checker threw a syntax error "unexpected token" on the break line after this line
opsUsers.add(userManager.getUserByKey(USER_KEY_3A))
Where the other similar lines for the other site case was
opsUsers << userManager.getUserByKey(USER_KEY_3B)
So I changed it to match opsUsers << and the error went away.
When running the script, it adds the securityUsers as expected (I had to properly place the postfunction after Create Issue Function. A little trial and error solved that.
The opsUsers isnt populated, heres the error
2021-02-03 19:09:04,523 ERROR [workflow.AbstractScriptWorkflowFunction]: Workflow script has failed for user 'jcejka'. View here: https://devportal.researchinnovations.com/jira/secure/admin/workflows/ViewWorkflowTransition.jspa?workflowMode=live&workflowName=HR+-+Out+Processing+Workflow&descriptorTab=postfunctions&workflowTransition=1&highlight=2
com.google.common.util.concurrent.UncheckedExecutionException: java.lang.NullPointerException: null value in entry: issue=null
at 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:103)
at com.atlassian.jira.issue.customfields.persistence.EagerLoadingOfBizCustomFieldPersister.getValuesForTypeAndParent(EagerLoadingOfBizCustomFieldPersister.java:86)
at com.atlassian.jira.issue.customfields.persistence.OfBizCustomFieldValuePersister.updateValues(OfBizCustomFieldValuePersister.java:151)
at com.atlassian.jira.issue.customfields.persistence.EagerLoadingOfBizCustomFieldPersister.updateValues(EagerLoadingOfBizCustomFieldPersister.java:61)
at com.atlassian.jira.issue.customfields.persistence.OfBizCustomFieldValuePersister.createValues(OfBizCustomFieldValuePersister.java:108)
at com.atlassian.jira.issue.customfields.persistence.EagerLoadingOfBizCustomFieldPersister.createValues(EagerLoadingOfBizCustomFieldPersister.java:49)
at com.atlassian.jira.issue.customfields.persistence.OfBizCustomFieldValuePersister.createValues(OfBizCustomFieldValuePersister.java:101)
at com.atlassian.jira.issue.customfields.persistence.EagerLoadingOfBizCustomFieldPersister.createValues(EagerLoadingOfBizCustomFieldPersister.java:43)
at com.atlassian.jira.issue.customfields.impl.AbstractMultiCFType.createValue(AbstractMultiCFType.java:127)
at com.atlassian.jira.issue.customfields.impl.AbstractMultiCFType.createValue(AbstractMultiCFType.java:39)
at com.atlassian.jira.issue.fields.ImmutableCustomField.createValue(ImmutableCustomField.java:693)
at com.atlassian.jira.issue.fields.ImmutableCustomField.updateValue(ImmutableCustomField.java:410)
at com.atlassian.jira.issue.fields.ImmutableCustomField.updateValue(ImmutableCustomField.java:396)
at com.atlassian.jira.issue.fields.OrderableField$updateValue$5.call(Unknown Source)
at Script233.run(Script233.groovy:64)
Caused by: java.lang.NullPointerException: null value in entry: issue=null
at 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$0(EagerLoadingOfBizCustomFieldPersister.java:104)
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)
... 17 more
Cancel
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The above script works as intended.
Needed to adjust
opsUsers.add(userManager.getUserByKey(USER_KEY_3A))
to
opsUsers << userManager.getUserByKey(USER_KEY_3A)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Any particular reason why it has to be after the "Creates the Issue originally"?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Jeremy Cejka I believe the reason is you're working with issue data - getting value from the site custom field
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
So the reason I ask, is that the next post function step is to copy these users to the watchers field. so that the notification scheme is a little more dynamic.
When the copy JSU function runs which is after this, it copies both of the user fields plus some others. It does not put these users that are generated based on site selection into the watcher field, just the others that are requestor filled or prefilled.
as a test
I tried using the same logic from the above script and adding a third array that just adds all other users in each case. That didnt work either.
The end game so that users in the security or ops field have an email notification.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Jeremy Cejka ,
would you please share me all the post functions you are doing now during create and in which order? I'm sorry, it is a little bit confusing for me now. Thank you.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Jeremy Cejka ,
please try to modify the script like this:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.customfields.option.Option
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.user.util.UserManager
Long CUSTOM_FIELD_ID_SITE = 14203
Long CUSTOM_FIELD_ID_SECURITY = 14308
Long CUSTOM_FIELD_ID_OPS = 14303
Long CUSTOM_FIELD_SITE_OPTION_ID_ALX = 11111
Long CUSTOM_FIELD_SITE_OPTION_ID_MLB = 22222
Long CUSTOM_FIELD_SITE_OPTION_ID_SATX = 33333
Long CUSTOM_FIELD_SITE_OPTION_ID_REMOTE = 44444
String USER_KEY_1A = "JIRAUSER11111"
String USER_KEY_1B = "JIRAUSER22222"
String USER_KEY_1C = "JIRAUSER33333"
String USER_KEY_2A = "JIRAUSER44444"
String USER_KEY_2B = "JIRAUSER55555"
String USER_KEY_2C = "JIRAUSER66666"
String USER_KEY_3A = "JIRAUSER77777"
String USER_KEY_3B = "JIRAUSER88888"
IssueManager issueManager = ComponentAccessor.getIssueManager()
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()
UserManager userManager = ComponentAccessor.getUserManager()
CustomField siteField = customFieldManager.getCustomFieldObject(CUSTOM_FIELD_ID_SITE)
CustomField securityField = customFieldManager.getCustomFieldObject(CUSTOM_FIELD_ID_SECURITY)
CustomField opsField = customFieldManager.getCustomFieldObject(CUSTOM_FIELD_ID_OPS)
ApplicationUser user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
Option siteFieldValue = issue.getCustomFieldValue(siteField) as Option
Long siteFieldOptionId = siteFieldValue.getOptionId()
List<ApplicationUser> securityUsers = []
List<ApplicationUser> opsUsers = []
switch (siteFieldOptionId) {
case CUSTOM_FIELD_SITE_OPTION_ID_ALX:
securityUsers << userManager.getUserByKey(USER_KEY_1A)
securityUsers << userManager.getUserByKey(USER_KEY_2A)
opsUsers << userManager.getUserByKey(USER_KEY_3A)
break
case CUSTOM_FIELD_SITE_OPTION_ID_MLB:
securityUsers << userManager.getUserByKey(USER_KEY_1B)
securityUsers << userManager.getUserByKey(USER_KEY_2B)
opsUsers << userManager.getUserByKey(USER_KEY_3B)
break
case CUSTOM_FIELD_SITE_OPTION_ID_SATX:
securityUsers << userManager.getUserByKey(USER_KEY_1C)
opsUsers << userManager.getUserByKey(USER_KEY_2C)
break
case CUSTOM_FIELD_SITE_OPTION_ID_REMOTE:
// TODO ?
break
}
issue.setCustomFieldValue(securityField, securityUsers)
issue.setCustomFieldValue(opsField, opsUsers)
issueManager.updateIssue(user, issue, EventDispatchOption.DO_NOT_DISPATCH, false)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
hey @Hana Kučerová
I appreciate all the support on this need.
I have two new issues.
1) Email notifications are not firing on issues that invoke this workflow. When researching it, everything looks ok with the notification scheme on create, its just not doing it, I suspect it has something to the with order of events in the workflow postfunction of create?
I know the above script wont work before the task "create issue originally". and I suspect under the hood, the notification event triggers with this postfunction. Ironically this ticket type both requires user input for people selector and the above automation people selection based on site. So I was surprised it didnt fire events to the assignee, requestor. But then again all of my custom fields get copied to the watchers. Theirs probably a couple of ways to skin this cat, but I need to figure out how to get the above fields to fire notifications. If you can assist on this that would be awesome.
Issue 2) as of recent, my script has been firing failures, I dont know how to debug based on the log details that show up in the workflow area for this workflow/script.
As a example, it shows "6 out of 7 executions have failed:" I click that
Logs:
"2021-04-14 15:26:37,016 ERROR [workflow.AbstractScriptWorkflowFunction]: Workflow script has failed on issue HR-307 for user 'jbond'. View here: https://devportal.researchinnovations.com/jira/secure/admin/workflows/ViewWorkflowTransition.jspa?workflowMode=live&workflowName=HR+-+Out+Processing+Workflow&descriptorTab=postfunctions&workflowTransition=1&highlight=6 java.lang.NullPointerException at com.atlassian.jira.issue.customfields.impl.MultiUserCFType.getChangelogValue(MultiUserCFType.java:161) at com.atlassian.jira.issue.customfields.impl.MultiUserCFType.getChangelogValue(MultiUserCFType.java:103) at com.atlassian.jira.issue.fields.ImmutableCustomField.getChangelogValue(ImmutableCustomField.java:376) at com.atlassian.jira.issue.fields.ImmutableCustomField.updateValue(ImmutableCustomField.java:411) at com.atlassian.jira.issue.fields.ImmutableCustomField.updateValue(ImmutableCustomField.java:396) at com.atlassian.jira.issue.managers.DefaultIssueManager.updateFieldValues(DefaultIssueManager.java:728) at com.atlassian.jira.issue.managers.DefaultIssueManager.updateIssue(DefaultIssueManager.java:681) at com.atlassian.jira.issue.managers.DefaultIssueManager.updateIssue(DefaultIssueManager.java:667) at com.atlassian.jira.issue.managers.RequestCachingIssueManager.updateIssue(RequestCachingIssueManager.java:217) at com.atlassian.jira.issue.IssueManager$updateIssue$0.call(Unknown Source) at Script6.run(Script6.groovy:74)"
Payload
"{ "canned-script": "com.onresolve.scriptrunner.canned.jira.workflow.postfunctions.CustomScriptFunction (java.lang.String)", "class.name": "com.onresolve.jira.groovy.GroovyFunctionPlugin (java.lang.String)", "full.module.key": "com.onresolve.jira.groovy.groovyrunnerrungroovy-function (java.lang.String)", "issue": "HR-307 (com.atlassian.jira.issue.IssueImpl)", "transientVars": { "issue": "HR-307 (com.atlassian.jira.issue.IssueImpl)", "configuration": "com.opensymphony.workflow.config.DefaultConfiguration@2b8ee553", "issueProperties": "{} (com.google.common.collect.RegularImmutableMap)", "currentSteps": "[SimpleStep@1[owner=, actionId=0, status=open]] (java.util.ArrayList)", "store": "com.opensymphony.workflow.spi.ofbiz.OfbizWorkflowStore@199dd440", "descriptor": "com.atlassian.jira.workflow.ImmutableWorkflowDescriptor@4147f2c3", "entry": "com.opensymphony.workflow.spi.SimpleWorkflowEntry@6581ebf2", "context": "com.opensymphony.workflow.basic.BasicWorkflowContext@590104c4", "createdStep": "SimpleStep@1[owner=, actionId=0, status=open] (com.opensymphony.workflow.spi.SimpleStep)", "originalissueobject": "null (org.codehaus.groovy.runtime.NullObject)", "actionId": "1 (java.lang.Integer)", "pkey": "HR (java.lang.String)", "changeItems": "[] (java.util.LinkedList)" }, "log": "org.apache.log4j.Logger@78ca2221", "\u00a3beanContext": "com.onresolve.scriptrunner.beans.BeanFactoryBackedBeanContext@62c6e6ca" }
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Jeremy Cejka ,
1) Please try to replace
issueManager.updateIssue(user, issue, EventDispatchOption.DO_NOT_DISPATCH, false)
with
issueManager.updateIssue(user, issue, EventDispatchOption.ISSUE_UPDATED, true)
2) Could it be that user jbond is not active anymore, so it so not possible to store him to the custom field?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
That user is just a test user. For whatever reason people in my modern/hip company hate to see the word Test are a user. They get all twitchy. So in an effort to appease them I make obscure random users to confuse them.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Hana Kučerová no change after changing the last line.
Same error reported for the script
2021-04-15 16:34:15,119 ERROR [workflow.AbstractScriptWorkflowFunction]: Workflow script has failed on issue HR-316 for user 'jcejka'. View here: https://devportal.researchinnovations.com/jira/secure/admin/workflows/ViewWorkflowTransition.jspa?workflowMode=live&workflowName=HR+-+Out+Processing+Workflow&descriptorTab=postfunctions&workflowTransition=1&highlight=6 java.lang.NullPointerException at com.atlassian.jira.issue.customfields.impl.MultiUserCFType.getChangelogValue(MultiUserCFType.java:161) at com.atlassian.jira.issue.customfields.impl.MultiUserCFType.getChangelogValue(MultiUserCFType.java:103) at com.atlassian.jira.issue.fields.ImmutableCustomField.getChangelogValue(ImmutableCustomField.java:376) at com.atlassian.jira.issue.fields.ImmutableCustomField.updateValue(ImmutableCustomField.java:411) at com.atlassian.jira.issue.fields.ImmutableCustomField.updateValue(ImmutableCustomField.java:396) at com.atlassian.jira.issue.managers.DefaultIssueManager.updateFieldValues(DefaultIssueManager.java:728) at com.atlassian.jira.issue.managers.DefaultIssueManager.updateIssue(DefaultIssueManager.java:681) at com.atlassian.jira.issue.managers.DefaultIssueManager.updateIssue(DefaultIssueManager.java:667) at com.atlassian.jira.issue.managers.RequestCachingIssueManager.updateIssue(RequestCachingIssueManager.java:217) at com.atlassian.jira.issue.IssueManager$updateIssue$0.call(Unknown Source) at Script18.run(Script18.groovy:74)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Looks like the updateIssue is failing, could you please log.error(user) and log.error(issue) and check, if they are not null?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
forgive my ignorance (which Ive never done this) I assume the lines
log.error(user)
log.error(issue)
above
issue.setCustomFieldValue(securityField, securityUsers)
issue.setCustomFieldValue(opsField, opsUsers)
issueManager.updateIssue(user, issue, EventDispatchOption.DO_NOT_DISPATCH, false)
?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yes, exactly, please, before the last line like:
issue.setCustomFieldValue(securityField, securityUsers)
issue.setCustomFieldValue(opsField, opsUsers)
log.error(user)
log.error(issue)
issueManager.updateIssue(user, issue, EventDispatchOption.DO_NOT_DISPATCH, false)
I apologize I wasn't clear enough.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
2021-04-15 18:25:54,348 ERROR [runner.ScriptBindingsManager]: jcejka(jcejka) 2021-04-15 18:25:54,351 ERROR [runner.ScriptBindingsManager]: HR-318 2021-04-15 18:25:54,377 ERROR [workflow.AbstractScriptWorkflowFunction]: Workflow script has failed on issue HR-318 for user 'jcejka'. View here: https://devportal.researchinnovations.com/jira/secure/admin/workflows/ViewWorkflowTransition.jspa?workflowMode=live&workflowName=HR+-+Out+Processing+Workflow&descriptorTab=postfunctions&workflowTransition=1&highlight=6 java.lang.NullPointerException at com.atlassian.jira.issue.customfields.impl.MultiUserCFType.getChangelogValue(MultiUserCFType.java:161) at com.atlassian.jira.issue.customfields.impl.MultiUserCFType.getChangelogValue(MultiUserCFType.java:103) at com.atlassian.jira.issue.fields.ImmutableCustomField.getChangelogValue(ImmutableCustomField.java:376) at com.atlassian.jira.issue.fields.ImmutableCustomField.updateValue(ImmutableCustomField.java:411) at com.atlassian.jira.issue.fields.ImmutableCustomField.updateValue(ImmutableCustomField.java:396) at com.atlassian.jira.issue.managers.DefaultIssueManager.updateFieldValues(DefaultIssueManager.java:728) at com.atlassian.jira.issue.managers.DefaultIssueManager.updateIssue(DefaultIssueManager.java:681) at com.atlassian.jira.issue.managers.DefaultIssueManager.updateIssue(DefaultIssueManager.java:667) at com.atlassian.jira.issue.managers.RequestCachingIssueManager.updateIssue(RequestCachingIssueManager.java:217) at com.atlassian.jira.issue.IssueManager$updateIssue$1.call(Unknown Source) at Script21.run(Script21.groovy:76)
So the user attribute is the creator, issue is the issuekey. The first two lines look like they have values.
Circling back to the meat of the script
switch (siteFieldOptionId) {
case CUSTOM_FIELD_SITE_OPTION_ID_ALX:
securityUsers << userManager.getUserByKey(USER_KEY_1A)
securityUsers << userManager.getUserByKey(USER_KEY_2A)
opsUsers << userManager.getUserByKey(USER_KEY_3A)
break
case CUSTOM_FIELD_SITE_OPTION_ID_MLB:
securityUsers << userManager.getUserByKey(USER_KEY_1B)
securityUsers << userManager.getUserByKey(USER_KEY_2B)
opsUsers << userManager.getUserByKey(USER_KEY_3B)
break
case CUSTOM_FIELD_SITE_OPTION_ID_SATX:
securityUsers << userManager.getUserByKey(USER_KEY_1C)
opsUsers << userManager.getUserByKey(USER_KEY_2C)
break
case CUSTOM_FIELD_SITE_OPTION_ID_REMOTE:
// TODO ?
break
}
issue.setCustomFieldValue(securityField, securityUsers)
issue.setCustomFieldValue(opsField, opsUsers)
issueManager.updateIssue(user, issue, EventDispatchOption.DO_NOT_DISPATCH, false)
I did a test for Remote, which has no users to set and it went thru fine, its only when i get to a site where the users are set in the array.
Oddly this seemingly become a problem after one of the following: upgrading jira from 8.5.4 to 8.13.3 or scriptrunners update as a post upgrade process. I am running the latest scriptrunner version.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ok with the help of learning about the log.error
I added log.error(securityUsers) and log.error(opsUsers)
2021-04-15 18:57:36,743 ERROR [runner.ScriptBindingsManager]: jcejka(jcejka) 2021-04-15 18:57:36,745 ERROR [runner.ScriptBindingsManager]: HR-319 2021-04-15 18:57:36,745 ERROR [runner.ScriptBindingsManager]: [dbirk(dbirk), cjones(cjones), null] 2021-04-15 18:57:36,745 ERROR [runner.ScriptBindingsManager]: [hpaterson(hpaterson)]
Weird behavior the security Users has null in addition to the two.
Probably the root of the problem.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Well ok. the crux of the problem has to deal with
String SATX_SEC1 = "esanchez"
and usage of
securityUsers << userManager.getUserByKey(SATX_SEC1)
Ive verified the user is valid based on the username above.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Jeremy Cejka Thank you - I believe I understand now where the problem is. I'm trying to find the user based on the provided user key. Originally the user names were the same as user keys, but in newer versions of Jira it is something like JIRAUSER12345. So "esanchez" is probably not valid user key and user is not found.
If you use this url, you should be able to get key for the user esachnez:
https://your-instance-url/rest/api/2/user?username=esanchez
The other thing is we should add some more checks to be sure, that the users exist and array is not empty etc...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
seems to be the issue. This particular user came onboard recently so the changes to key != name is true for her, but everyone else was prior to that change so they're the same.
Ive atleast learned enough so far to fix this :P. Atleast their api is well documented I can piece together the pieces of this problem.
I changed the calls from ByKey to ByName. And all is good. atleast for this piece.
Now I have to figure out the email notifications
Can you explain the differences between
issueManager.updateIssue(user, issue, EventDispatchOption.DO_NOT_DISPATCH, false)
and
issueManager.updateIssue(user, issue, EventDispatchOption.ISSUE_UPDATED, true)
From what I was reading that this may re-fire the notifications? But I was wondering under the hood what the differences were.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ive answered my own question. Found the api reference that details. this
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hypothetically, if I wanted to make this script more dynamic, instead of hardcoding users here in the script, use group members from ldap to populate my fields. I think I have enough to get started but need some help understanding arrays with a field being populated from a group with multiple members
Heres what I got so far in changing
Added
GroupManager groupManager = ComponentAccessor.getGroupManager()
In order to get the first iteration to fire (just to add members to multiuser picker) I had to change the following
def securityUsers = [] def opsUsers = [] switch (siteFieldOptionId) { case CUSTOM_FIELD_SITE_OPTION_ID_ALX: //opsUsers << userManager.getUserByKey(ALX_OP1) //securityUsers << userManager.getUserByName(ALX_SEC1) //securityUsers << userManager.getUserByName(ALX_SEC2) //securityUsers << userManager.getUserByName(SATX_SEC1) securityUsers = groupManager.getUsersInGroup(ALX_FSO) opsUsers = groupManager.getUsersInGroup(ALX_OPS) break
The group here has multiple users, but its a single line input, when I left the List securityUsers= [] the syntax checker threw and error for the variable definitions in the switch statement. So I changed it to def <variable> = [], (its not right. )
When I tried to add
securityUsers << groupManager.getUsersInGroup(ALX_FSO) securityUsers << groupManager.getUsersInGroup(SATX_SEC1)
I got this
class java.util.ArrayList cannot be cast to class com.atlassian.jira.user.ApplicationUser
Ive got a work around,
securityUsers = groupManager.getUsersInGroup(ALX_FSO)
and that is for a single group I can add multiple users to securityUsers, I just cant do the array. So the work around would be to add users from the other group to the group that matches the site.
Thoughts?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Jeremy Cejka Plase try something like:
List<ApplicationUser> securityUsers = []
...
securityUsers.addAll(groupManager.getUsersInGroup(ALX_FSO))
securityUsers.addAll(groupManager.getUsersInGroup(ALX_FSO2))
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.