Can't input multiples values in a Textfield CustomField

Deleted user March 25, 2013

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

1 vote
Answer accepted
JamieA
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.
March 25, 2013

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.

JamieA
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.
March 25, 2013

No worries, hope you get it working.

Deleted user March 25, 2013

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
TAGS
AUG Leaders

Atlassian Community Events