Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
Next:
badges earned

Your Points Tracker
Challenges
Leaderboard
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Recognition
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Kudos
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Scriptrunner - Post Function - Clone and Issue, and links

Hello,

Im creating 5 automatic Issuelinks with a PostFunction Scriptunner (Clone and Issue, and links) with that everythink is okey, the problem is I want to perform a "Aditional issue action" where (here is de difficult part) Want to copy a value from the Main Issue, but this customfield(text field single line) have a formated input like (CODE=VALUE;CODE=VALUE;...), in the linked issues need to sum each VALUE and then assign 20% of the sum in each issuelink.

Not sure if you this is posible from there, maybe other kind of function can resolve this.

From now thanks and have a nice day.Where I want to put the code.png

1 answer

1 accepted

1 vote
Answer accepted

Hi @Nicolás Figueroa,

I hope that my understanding is correct:

  1. Parent issue will have a custom field with value as per the following; CODE=VALUE;CODE=VALUE;...
  2. For the issues that we are automating the creation, we would like to process the string and assign 20% of the sum to each linked issues.
  3. So basically what the code needs to do is to get the content of the field, sum all the VALUE and then assign 20% of the sum to each linked issue.
  4. The custom field is the same for the parent and child issues.

Correct me if I'm getting anything wrong here. If I got it all right, then this should be script:

def cf = customFieldManager.getCustomFieldObjects(sourceIssue).find {it.name == 'custom field name'}
def cfValues = sourceIssue.getCustomFieldValue(cf)
def cfValue = cfValues.split(';')

float value


for ( String item : cfValue ) {
value = item.split('=')[1]
value += value
}

def finalValue = value * 0.2


issue.setCustomFieldValue(cf, finalValue)

FYI, I didn't test the script. I hope that this helps.

Thanks,
Moga

Hello @mogavenasan 

Thanks for your quick response and yes you are undestading well the case.

I try the script and change the value for String because its give error (cause float value = String item) and then convert it a float, but im not sure if im doing it well.

Also the script gives this error:

script split.png

Updated: now have no error, but the field its not updated:

 

def cf = customFieldManager.getCustomFieldObjects(sourceIssue).find {it.name == 'custom field name'}
def cfValues = sourceIssue.getCustomFieldValue(cf) as String
def cfValue = cfValues.split(';')

float values


for ( String item : cfValue ) {
def value = item.split('=')[1]
values = value as Float
values += (float) values
}

def finalValue = values * 0.2


issue.setCustomFieldValue(cf, finalValue)

After some modification I can make it run:

def cf = customFieldManager.getCustomFieldObjects(sourceIssue).find {it.name == 'Custom FieldName'}
def cfValue = sourceIssue.getCustomFieldValue(cf)
//Use string array to hold all values and convert them to String
String[] cfValues = cfValue.toString().split(';')

double values = 0.0

for ( String item : cfValues ) {
//Convert the VALUES to duble
Double value = Double.parseDouble(item.split("=")[1])
values += value
}

//Convert to string because the customfield is SimpleText
def finalValue = String.valueOf(values * 0.2)

issue.setCustomFieldValue(cf, finalValue)
Like mogavenasan likes this

Hi @Nicolás Figueroa 

You have mentioned "Im creating 5 automatic Issuelinks with a PostFunction Scriptunner (Clone and Issue, and links)", How have you been creating 5 issue links with the single post-function? or you have used 5 post-function.

Thanks

Hello @Tejas Naik

I have created 5 different post-functions with Scriptrunner.

Maybe you can create only 1 post-function that create 5 issuelinks but I believe you need to write some code.

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Marketplace Apps & Integrations

☕️ Monday coffee with Jexo: Weekly Atlassian news roundup | 21st June 2021

Hi community 👋, as every Monday we're bringing you a quick update on what happened in the Atlassian ecosystem last week. There were a few interesting events like for example the announcement of th...

51 views 0 6
Read article

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