Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Add value to a textfield on condition of a multi-select field on Issue creation.

Stuart_Hart April 20, 2020

I would like to implement some automation wherein a custom multi-line text field is preset with particular value(s) when the user selects one or more option from a multi-select custom field.

For example, on the Create Screen for the ticket, there is a multi-select menu with the following options:

  • Option A
  • Option B
  • Option C

The user picks Option A and Option C, then they Create the issue. The resulting ticket then has some additional information in a custom multi-line text field:

Some info pertaining to Option A.

Some other info pertaining to Option C.

Is there some sort of script or plugin I can use to achieve this? I tried using ScriptRunner before but didn't get very far.

4 answers

1 accepted

0 votes
Answer accepted
Stuart_Hart May 4, 2020

Thanks for all the replies, everyone.

In the end, I ended up using a long series of Precondition Value Field (JSU) and Update Any Issue Field (JSU) post functions.

It's cumbersome and I'm really keen to update it to something much more future proof and manageable, but for now it works. It's likely to remain like this until we have a dedicated Jira Admin!

Denise_Wuethrich_beecom_products
Contributor
May 4, 2020

Hi, @Stuart_Hart JSU also has JQL Preconditions. 
It's possible to cover several different preconditions with 1 JQL Precondition.

There are some Use Cases here: https://confluence-apps.beecom.ch/display/JSU/JQL+Use+Cases

 

For further assistance with simplifying this with JQL, raise a support ticket here: https://servicedesk-apps.beecom.ch/servicedesk/customer/portal/3/user/login?destination=portal%2F3

0 votes
Andrew Laden
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 20, 2020

You could probably do something with the "live fields" functionality in Power scripts for Jira.

One question to ask is what behavior you want when a user types some information into the custom field, and then changes the options. Do you preserve that data or not.

While a little messier, you way want to consider a custom multiline text field for each option, and then use live fields to show/hide the field based on the value of the checkbox.

Yes its custom field sprawl, but it will better protect your users when the enter data and then change thier mind on the options.

Stuart_Hart April 21, 2020

This sounds interesting!

From what I'm reading, it sounds like information on the Create/Edit Screens can update depending on what options are selected in custom fields? Am I understanding this correctly?

I'm actually not sure what add-ons we have installed at our company (I'm not the Jira Admin), but if I make any progress on this matter, I'll update this thread with the solution I come to.

Andrew Laden
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 21, 2020

Yes, you can modify the create/edit screens depending on options. Its a little tricky to get used to but works.

Also forgot about Deviniti Synamic Forms. That may help as well.

https://marketplace.atlassian.com/apps/1210820/dynamic-forms-for-jira?hosting=server&tab=overview

0 votes
John Funk
Community Champion
April 20, 2020

Hi Stuart  - Welcome to the Atlassian Community!

Automation for Jira should be able to do that for you or the Jira Miscellaneous Workflow Extensions (JWME). Automation for Jira has a Lite version that is free, but both apps will require a fee for the full server version. 

Stuart_Hart April 21, 2020

Thanks John. I believe we have this add-on installed, so I'll explore this as a potential solution.

0 votes
Leonard Chew
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 20, 2020

With scriptrunner you can do that by adding a postfunction on your create-issue transition on the workflow.

The postfunction script would be between the initial creation postfunction step and the reindex postfunction step.

The logic of the script:

  • Read the content of the multi-select custom field.
  • Write the content into the text field based on the values.

 

Stuart_Hart April 21, 2020

Yes, I had previously tried implementing something with Scriptrunner and the logic you've bullet-pointed it basically what I was trying to do. However, I couldn't get the syntax correct.

Leonard Chew
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 2, 2020

If you still need it, here would be the code:

You'll have to put the postfunction between the "Create" Step and the "Reindex" Step.

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import org.apache.log4j.Level
log.setLevel(Level.DEBUG)

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

def dropDownField = customFieldManager.getCustomFieldObjectsByName('Your Dropdown Field')[0]
def textField = customFieldManager.getCustomFieldObjectsByName('Your Text Field')[0]

def dropDownValue = dropDownField.getValue(issue).toString()

String newText
switch (dropDownValue) {
case "Option 1":
newText = "Text for Option 1"
break
case "Option 2":
newText = "Text for Option 2"
break
}

log.debug('setting the value of field "'+textField.name +'" to "'+newText+'"')
issue.setCustomFieldValue(textField,newText)
issueManager.updateIssue(user, issue, EventDispatchOption.DO_NOT_DISPATCH,false)

Suggest an answer

Log in or Sign up to answer