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,296,016
Community Members
 
Community Events
165
Community Groups

ScriptRunner Behavior on a select list

Edited

The output should be a table (in issue description):

Безымянный (1).pngБезымянный (2).png

import com.atlassian.jira.issue.customfields.option.LazyLoadedOption
import com.atlassian.jira.component.ComponentAccessor;

customFieldManager = ComponentAccessor.getCustomFieldManager();

def customField_4 = customFieldManager.getCustomFieldObjectByName("Processing")

def myCustomFieldValue = issue.getCustomFieldValue(customField_4)
def customFieldValue_4 = myCustomFieldValue != null ? ((LazyLoadedOption) myCustomFieldValue).getValue() : null

def valueToStringMap = [

  "PAYIN":"Payin",

  "QW":"qw_pull"

]

if (valueToStringMap.containsKey(customFieldValue_4)) {

  customFieldValue_4 = valueToStringMap.get(customFieldValue_4)

}

def description_text_1 = '||Contract||Value||\n'
description_text_1 += '|code type|'+customFieldValue_4.toString()+'|\n'

if(issue.description) issue.description = description_text_1 + issue.description

else issue.description = description_text_1

But the code doesn't work for some reason :(

2 answers

I created listener , but all the same result «null».

@Alex Koxaras 

F6C9FE04-433A-4F64-8B29-C45F134CFBAB.jpeg

@Alex Koxaras , please, can you  help me?

0 votes

Hi @Oliver Smith 

What is the result you are getting? What do you mean it doesn't work? Is there any error on your code, or simply the table isn't populated in the description? Or the table isn't in the correct format?

And where do you place this code? On a listener?

Hello @Alex Koxaras 

on the "create issue" screen, I select the Processing field and select option (payin or QW) there, depending on the choice, the value should be written to the table (description), I write the code in post funcrtion

 

onew.pngonew.pngsdad.png

@Alex Koxaras  I choose option "QW" (in Cf)  , but for some reason it writes "nulll" in the table and not qw_pull , as by condition

Alex Koxaras Community Leader May 31, 2022

@Oliver Smith 

I tried the same thing on a DC instance, with the latest script runner, and within the Clone prebuilt listener, and it seems to work well.

qw_pull.png

@Alex Koxaras 

Is this table created in a clone of issue ? it's just that I have it (table) in the clone is created (issue link cloned by)sdad.png

Alex Koxaras Community Leader May 31, 2022

@Oliver Smith when does this clone listener is triggered? In which events? And how exactly you want it to work?

I mean you have a parent issue (e.g. PAR-1). When you edit this issue, then this issue gets cloned and created PAR-2 as a task with the table as the description

Is the above statement correct? If not, kindly clarify.

@Alex Koxaras 
steps: I fill in the fields when creating a task in mine (qpartner project), then after pressing the "creat" button, the task is automatically escalated to (TSP project) and a value table is automatically created in it based on what we filled out earlier

Alex Koxaras Community Leader May 31, 2022

@Oliver Smith thank you! I managed to reproduce your error and I get a null as well. Let me try something and get back to you.

@Alex Koxaras  Yes of course thank you.

Alex Koxaras Community Leader May 31, 2022

@Oliver Smith here's the deal:

null value.png

When creating the issue, most likely the system (even if you move the PF after the reindex) didnt update the Processing field value. This result in a null value, even from the very beginning. That's why you are getting the null on your table.

Now, I would consider two alternative to this:

  • Instead of a post function within the workflow, use a listener on a Issue created event. This most likely will do the trick. It is recommended to test it first, prior of implementing it on production
  • The second solution is to create a new transition (or a self transition) on the status right after the create transition. Let's call this new transition "Create Clone Issue". As a post function on this "Create Clone Issue" transition you will place your groovy script PF as you have it now on the create transition. In addition you will place a "Hide from user" condition, so as this transition can only be activated automatically. Now on the create transition, I would simply call a transition PF, to transition the issue through the "Create Clone Issue" after the initial creation. By doing this, you will have for sure a value for the processing field, and the clone will work.

Let me know if the above are clear.

Alex

@Alex Koxaras  

Can you please show on the screenshots? otherwise I do not quite understand 

Suggest an answer

Log in or Sign up to answer
TAGS

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you