I want to be able to use the contents of a drop down field to populate another drop down field in the same issue on transition using custom script post-function in Script Runner:
If field A contains "Option 1", "Option 2", "Option 3", "Option 4", "Option 5", "Option 6", "Option 7", "Option 8", "Option 9" or "Option 10" then field B should be set to "Updated". If field A contains none of these options, field B remains unchanged.
I have tried a number of options using code I have found in different posts but nothing seems to work. Can anyone help me with this please?
Here code for this:
package CustomFields.getValue import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.event.type.EventDispatchOption import com.atlassian.jira.issue.MutableIssue import com.atlassian.jira.issue.customfields.option.Option List<String> selectedOptions = Arrays.asList("Option 1", "Option 2", "Option 3", "Option 4", "Option 5", "Option 6", "Option 7", "Option 8", "Option 9", "Option 10") MutableIssue issue = ComponentAccessor.getIssueManager().getIssueObject("ZVER-93") for(Option option: ((List<Option>) issue.getCustomFieldValue(ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("ТестМульВыбор")))){ selectedOptions.contains(option.toString()){ issue.setCustomFieldValue(ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("field B"), "Updated") ComponentAccessor.getIssueManager().updateIssue( ComponentAccessor.getJiraAuthenticationContext().getUser().getDirectoryUser() ,issue ,EventDispatchOption.ISSUE_UPDATED ,false ) } }
Could you provide types of custiom fields?
Thanks Vasiliy. I'm using single choice select lists for each of my fields, will that change anything in the above script you've kindly written?
Just want to check, I assume "ТестМульВыбор" should be the title of field A? Also, what is "ZVER-93" so that I can replace this in my code as I assume this is unique to you?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
ZVER-93 is a key for my test issue. Here is a cleared code:
import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.event.type.EventDispatchOption import com.atlassian.jira.issue.MutableIssue import com.atlassian.jira.issue.customfields.option.Option List<String> selectedOptions = Arrays.asList("Option 1", "Option 2", "Option 3", "Option 4", "Option 5", "Option 6", "Option 7", "Option 8", "Option 9", "Option 10") MutableIssue issue = ComponentAccessor.getIssueManager().getIssueObject("ZVER-93") for(Option option: ((List<Option>) issue.getCustomFieldValue(ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("ТестМульВыбор")))){ selectedOptions.contains(option.toString()){ issue.setCustomFieldValue(ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("field B"), "Updated") ComponentAccessor.getIssueManager().updateIssue( ComponentAccessor.getJiraAuthenticationContext().getUser().getDirectoryUser() ,issue ,EventDispatchOption.ISSUE_UPDATED ,false ) } }
I would recomed to test it with script console, see this: https://answers.atlassian.com/questions/32982259
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks Vasiliy.
Sorry, just want to confirm a couple of things:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Sorry, I am so careless last days. issue - is a varialbe, already defined into a postfunction and represents current issue.
import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.event.type.EventDispatchOption import com.atlassian.jira.issue.MutableIssue import com.atlassian.jira.issue.customfields.option.Option List<String> selectedOptions = Arrays.asList("Option 1", "Option 2", "Option 3", "Option 4", "Option 5", "Option 6", "Option 7", "Option 8", "Option 9", "Option 10") for(Option option: ((List<Option>) issue.getCustomFieldValue(ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("field A")))){ selectedOptions.contains(option.toString()){ issue.setCustomFieldValue(ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("field B"), "Updated") ComponentAccessor.getIssueManager().updateIssue( ComponentAccessor.getJiraAuthenticationContext().getUser().getDirectoryUser() ,issue ,EventDispatchOption.ISSUE_UPDATED ,false ) } }
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Try this
A more complex example, where if the user user sets the select list field Demo to No, we require them to fill in a text field Reason for no demo:
cfValues['Demo']?.value != 'No' || cfValues['Reason for No Demo']
c
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Saravanan. That's not what I want the script to do. I need it to amend another field automatically rather than present the user with another field to complete as the second field can only be one of 2 things, unchanged or "Updated".
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online 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.