ScriptRunner Behavior on a select list

Alex
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 30, 2022

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

0 votes
Alex
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 31, 2022

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

@Alex Koxaras _Relational_ 

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

Alex
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 31, 2022

@Alex Koxaras _Relational_ , please, can you  help me?

0 votes
Alex Koxaras _Relational_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 31, 2022

Hi @Alex 

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?

Alex
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 31, 2022

Hello @Alex Koxaras _Relational_ 

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
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 31, 2022
Alex
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 31, 2022

@Alex Koxaras _Relational_  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 _Relational_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 31, 2022

@Alex 

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
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 31, 2022

@Alex Koxaras _Relational_ 

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 _Relational_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 31, 2022

@Alex 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
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 31, 2022
Alex
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 31, 2022

@Alex Koxaras _Relational_ 
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
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 31, 2022
Alex Koxaras _Relational_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 31, 2022

@Alex 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
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 31, 2022

@Alex Koxaras _Relational_  Yes of course thank you.

Alex Koxaras _Relational_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 31, 2022

@Alex 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
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 31, 2022

@Alex Koxaras _Relational_  

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

Suggest an answer

Log in or Sign up to answer