Can't input multiples values in a Textfield CustomField

Good morning Atlassian Community,

Here's my problem :

I want to retrieve several different values contained in the same Jira Issue, then put everything together in a textfield customfield (<255 characters).

For that, here is the code I use :

import com.atlassian.jira.ComponentManager
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.security.groups.GroupManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.customfields.manager.OptionsManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.crowd.embedded.api.User
import com.atlassian.crowd.embedded.api.Group

MutableIssue issue = issue

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def cf = customFieldManager.getCustomFieldObjects(issue).find {it.name == 'Products'}
def cfValue = issue.getCustomFieldValue(cf)

def cf2 = customFieldManager.getCustomFieldObjects(issue).find {it.name == 'Project Type'}
def cfValue2 = issue.getCustomFieldValue(cf2)

def cf3 = customFieldManager.getCustomFieldObjects(issue).find {it.name == 'Branche Git'}

cf3 = "[" + issue.issueTypeObject.name + "]" + cfValue2 + "-" + cfValue +"-[" + issue.key + "]-["+ issue.dueDate +"]-["+ issue.reporter + "]"

Normally, this code is ok because it works in the Script Runner :

But, when executing it in the workflow, nothing happened (not even an error message in the logs). But, I've tested to put it instead of the summary and / or the issue description and it works :

Can you give me a clue about what I did wrong?

Another thing, when regarding the previous screenshot, I notice that the issue.key is null, which is normal because the script is executed like this :

I'm sure I'm missing, but can't figure out what exactly.

Thanks for your attention.

Cheers.

Fabien.

1 answer

1 accepted

This widget could not be displayed.

I see no code where you are setting a custom field value... something like issue.setCustomFieldValue(cf, "new value").

Your last line doesn't actually modify the issue.

Also see https://answers.atlassian.com/questions/124545/script-runner-post-function-create-issue-custom-field-value?page=1#124570

You might be better off with a scripted field, as the code will be easier, and it will stay up to date if any of the inputs change.

No worries, hope you get it working.

Hi Jamie,

Huge shame on me!

I've already tested the issue.setCustomFieldValue at the time, but it didn't work (no doubt I've made a mistake).

Thanks again for your speed and accurate answer, I've been searching and searching for a time but in the end, I was blind about the code I wrote.

Cheers.

Fabien.

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted yesterday in Jira

What modern development practices are at the heart of how your team delivers software?

Hey Community mates! Claire here from the Software Product Marketing team. We all know software development changes rapidly, and it's often tough to keep up. But from our research, we've found the h...

67 views 0 1
Join discussion

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you