Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,360,176
Community Members
 
Community Events
168
Community Groups

Need help with updating Scriptrunner Job

Edited

Hi,

We have a scriptrunner Job, that runs daily. The purpose of the job is to fetch some information from the db & update the issue as a cascading drop down. I want to change this field to a single drop down. Can I please get help with making the value to be inserted as a single drop down.

3 answers

1 accepted

2 votes
Answer accepted
Tuncay Senturk Community Leader Sep 12, 2022

Hello Aisha @AisM :) 

Of course, I'll be glad to help. So, I think you have a cascaded field but you want to change it to a single drop-down and you want to change the scriptrunner code accordingly.

Please share the code which will be a good start to update. I will check the code and help you change the relevant part.

Best

Hi @Tuncay Senturk  ,Yes!  thank you sooo much :) 

To give some info : The field values are being fetched into the jira database from another team’s database. In Jira the value is spit into a parent and child drop down and updated for the issue. Now we are planning on using a new custom field in Jira with a single drop down. 

Example - In db table ,field value is stored as Option1,Option2 

In Jira it’s split and updated as Option1 (Parent value) & Option2 (Child value) by the script job.

Below is a snippet of the old code (where the splitting happens) that populates the value into the cascading field for the Jira Epic issue type ONLY if it’s empty :)

9118BE85-0ABF-4572-B3AC-42B958F29930.jpeg

3930B3F4-051C-44DF-A480-1B60A59096BC.jpeg

Tuncay Senturk Community Leader Sep 13, 2022

Hi @AisM 

Thanks for providing the details. @Nic Brough _Adaptavist_  already provided how to update a regular drop-down using Script Runner.

As far as I understand, you will use parentOption (which is Option 1 in your DB) to update the drop-down and you will remove those childOption parts from the code.

Do you want me to help you code the related part? 

@Tuncay Senturk @Yes pleaseee :) that would be so so helpful 

Actually going forward, there will no Option1,Option2 . . Just one value without the comma (,) on the database tables

Example:

Option blah A

Option blah B

Option blah C 

So, for Epics will EMPTY values, this will get updated with the values from the db . Hope I made sense. 

Tuncay Senturk Community Leader Sep 14, 2022

Ok sure! Please give me some time. I will work on the code after business hours :) 

@Tuncay Senturk  Thank you so much :) Really appreciate you helping me with this . .  :) :)

Tuncay Senturk Community Leader Sep 17, 2022

Hello @AisM 

Sorry for the delay, I just had the time.

Below is the updated code relevant to the one you already shared.

Assuming,

  • you have got the DB value in strEIT variable and it holds the text of the drop-down, not the ID (just like in your code)
  • the strEC variable holds the issue which will be updated
  • epic control stays the same
  • 12898 is the id of your single drop-down field
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder

String strEIT = "value-from-db"
String strEC = "ABC-123"
def issue = ComponentAccessor.getIssueManager().getIssueByCurrentKey(strEC)
if (issue && issue.getIssueType().getName().equalsIgnoreCase("epic")) {
def customField = ComponentAccessor.getCustomFieldManager().getCustomFieldObject(12898)

def availableOptions = ComponentAccessor.optionsManager.getOptions(customField.getRelevantConfig(issue))
def optionToSet = availableOptions.find { it.toString() == strEIT }

customField.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(customField), optionToSet), new DefaultIssueChangeHolder())
}

 

 I hope it helps, please let me know if you have further questions.

Tuncay

Tuncay Senturk Community Leader Sep 20, 2022

Hi @AisM 

Have you had a chance to use the code above?

Hi @Tuncay Senturk , Thank you a million much for the script . . !!! Got sidetracked with some personal work, so was away from work . . 

I’m actually waiting on my access the DB to actually have a view at the data :). But let me just try this out for a single project and see if it works . . 
Also, 


String strEIT = "value-from-db"
String strEC = "ABC-123"

Should I change anything here before I try it in my instance ? 

Thank you so much for taking time to help ! :) 

Tuncay Senturk Community Leader Sep 22, 2022

Hi @AisM 

Those variable names come from the ones in your code. Getting the value from DB part was not in the code, so I had to remain it as below

String strEIT = "value-from-db"

 value-from-db should be the value coming from the DB.

below is the issue key, of course, it needs to be updated accordingly. Again, strEC was holding the issue key in your code, but the related part did not exist. So I just put it there as below:

String strEC = "ABC-123"

 Hope it helps

Hi @Tuncay Senturk  Thank you for the explanation :) 
Also, due to some management confusion at my org I’m unable to get access to the db and test this scenario . . 

So, I’ll accept your answer for now, as I’m sure it’ll work :) And thank you once again for being a life saver :):):)

Tuncay Senturk Community Leader Sep 24, 2022

Hi @AisM 

OK, I see! Please let me know if you have any issues.

Thanks

Hi @Tuncay Senturk !! Hope your are well :) This is me Aisha, I am having some problem accessing my original account. So, using this account for the time being :)

So, I have been looking for some way to update my existing script. Can you pleaseeee have a look & let me know what you think. :)

Suggest an answer

Log in or Sign up to answer