Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

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,560,231
Community Members
 
Community Events
185
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
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
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
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
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
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
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
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
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
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
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
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
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 :):):)

Like Tuncay Senturk likes this
Tuncay Senturk
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Sep 24, 2022

Hi @AisM 

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

Thanks

Like AisM likes this
1 vote
Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Sep 13, 2022

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. :)

Hi @Tuncay Senturk , Just wanted to ask a random doubt . . Didn’t find anything online while searching . . :)

Our workflow post functions have the resolution of the issue will be set to -1 . . What does that mean ? Also, what happens if i set it to None . . 

Tuncay Senturk
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Sep 29, 2022

Hi @AisM 

I don't know what "-1" value means but it may probably be the code that your Jira admins set.

The Resolution field is a very important field in Jira. If it is set to a value (no matter what), it means that the issue is closed. Resolution value specifies the reason an issue is closed. In Jira reports, this field is used for the Closed/Resolved tickets.

So, if you set its value to None, it means that the issue is still not closed and needs working on it.

I hope it makes sense.

@Tuncay Senturk  Thank youuu !

Oh okay, makes sense . . We aren’t sure how it got set to -1 . .

So, what happens if the resolution is not set for a particular status, like for example - FEEDBACK . . So, does that affect the reporting in any way, or is it always necessary to set a resolution value in the workflow post function for every status 

Tuncay Senturk
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Sep 30, 2022

Resolution is a Jira system field just like the Status. It does not provide values per status. An issue can have only one resolution value and by default, it is not set, null value.

If you set any value to an issue, it means that the issue is resolved. Generally, this field is set by the latest status in your workflow (e.g. RESOLVED, CLOSED, DONE, etc) and it should be cleared (set to none) if you reopen the issue.

I hope it was clear.

Hi @Tuncay Senturk  , Hope you are well !! :):) Lol, its been so longgg since I came to the community page . . .  Was on a long break from Jira :D 

Like Tuncay Senturk likes this
Tuncay Senturk
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Feb 20, 2023

Hi @AisM 

Welcome back! I am all good, hoping the same is true for you. Waiting for your questions then :)

Suggest an answer

Log in or Sign up to answer