Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

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,557,621
Community Members
 
Community Events
184
Community Groups

How to copy Organizations to custom field

Current situation:

ScriptRunner Post function 'Clones an issue, and links' used for cloning an issue from project X to project Y

Wish

Copy the field Organizations in JSD project X to custom field Reported Organization in project Y

Current implementation

The solution must be something like this

def cf = customFieldManager.getCustomFieldObjects(sourceIssue).find {it.name == 'Reported Organization'}
issue.setCustomFieldValue(sourceIssue.(Organizations)

However, I'm getting an error:

Script305.groovy: 4: unexpected token:  @ line 4, column 54.
   ue(sourceIssue.(Organizations)

Ideas anyone? Thanks.

2 answers

1 accepted

0 votes
Answer accepted

This is the script I used that works now:

def cfReporterOrganization = customFieldManager.getCustomFieldObjects(sourceIssue).find {it.name == 'Reported Organization'}
def cfOrganization = customFieldManager.getCustomFieldObjects(sourceIssue).find {it.name == 'Organizations'}
def cfOrganizationValue = sourceIssue.getCustomFieldValue(cfOrganization)

if (cfOrganizationValue) {
issue.setCustomFieldValue(cfReporterOrganization,cfOrganizationValue.first().name.toString())
}

0 votes
Gustavo Félix
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.
Sep 29, 2020

Hi @Berry Kersten 
I'm not sure if this is a typo when you wrote the code here, but 
issue.setCustomFieldValue(sourceIssue.(Organizations) 
is missing a parentheses at 
issue.setCustomFieldValue(sourceIssue.(Organizations) )

Hi @Gustavo Félix thanks!

I've changed the code a bit. However now it's populating the custom field 'Reported Organization' with "Organizations" in stead of the value of Organizations in the linked issue..

def cf = customFieldManager.getCustomFieldObjects(sourceIssue).find {it.name == 'Reported Organization'}
issue.setCustomFieldValue(cf,'Organizations')

If I change it to 

issue.setCustomFieldValue(cf,Organizations)

then the variabele is undeclared.

I guess I have to define Organizations first?

Gustavo Félix
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.
Sep 30, 2020
def cf = customFieldManager.getCustomFieldObjects(sourceIssue).find {it.name == 'Reported Organization'}
issue.setCustomFieldValue(cf,'Organizations')

That's because setCustomFieldValue has as first parameter the customField and then the value you want to set. In this case, you are saying that you want to set the text "Organizations" to your custom Field.

def cfReporterOrganization = customFieldManager.getCustomFieldObjects(sourceIssue).find {it.name == 'Reported Organization'}
def cfOrganization = customFieldManager.getCustomFieldObjects(sourceIssue).find {it.name == 'Organizations'}
issue.setCustomFieldValue(cfReporterOrganization ,sourceIssue.getCustomFieldValue(cfOrganization ))

If I understand right your situation, I think it should be like that
You are going to get the value from Organizations and set it to Reported.

Let me know if that worked .

Hi @Gustavo Félix thanks again!

When using that script I'm getting a NullPointerException: Cannot get property 'id' on null object. When removing the script, the existing post function does clone the issue successfully, so the error seems related to that script.

For completeness, in additional issue actions I have the following script:

//set reporter based on assignee
issue.reporter = sourceIssue.assignee

//set Isssue Security of Reported Issue in WOF form
def cf2 = customFieldManager.getCustomFieldObjects(sourceIssue).find {it.name == 'Set Reported Issue Public?'}

if (sourceIssue.getCustomFieldValue(cf2).toString().equals("Yes")) {
issue.setSecurityLevelId(10100)
} else {
issue.setSecurityLevelId(10002)
}

// set Reported Organization based on organization in JSD
def cfReporterOrganization = customFieldManager.getCustomFieldObjects(sourceIssue).find {it.name == 'Reported Organization'}
def cfOrganization = customFieldManager.getCustomFieldObjects(sourceIssue).find {it.name == 'Organizations'}
issue.setCustomFieldValue(cfReporterOrganization,sourceIssue.getCustomFieldValue(cfOrganization))

 

 

More details in the error log:

---
Caused by: com.atlassian.jira.workflow.WorkflowException: Error occurred while creating issue. This could be due to a plugin being incompatible with this version of JIRA. For more details please consult the logs, and see: http://confluence.atlassian.com/x/3McB
at com.atlassian.jira.workflow.OSWorkflowManager.createIssue(OSWorkflowManager.java:778)
at com.atlassian.jira.issue.managers.DefaultIssueManager.createIssue(DefaultIssueManager.java:592)
... 362 more
Caused by: java.lang.ClassCastException: class java.util.ArrayList cannot be cast to class java.lang.String (java.util.ArrayList and java.lang.String are in module java.base of loader 'bootstrap')
at com.atlassian.jira.issue.customfields.impl.GenericTextCFType.getDbValueFromObject(GenericTextCFType.java:51)
at com.atlassian.jira.issue.customfields.impl.AbstractSingleFieldType.createValue(AbstractSingleFieldType.java:144)
at com.atlassian.jira.issue.fields.ImmutableCustomField.createValue(ImmutableCustomField.java:693)
at com.atlassian.jira.workflow.function.issue.IssueCreateFunction.execute(IssueCreateFunction.java:84)
at com.opensymphony.workflow.AbstractWorkflow.executeFunction(AbstractWorkflow.java:1014)
at com.opensymphony.workflow.AbstractWorkflow.transitionWorkflow(AbstractWorkflow.java:1407)
at com.opensymphony.workflow.AbstractWorkflow.initialize(AbstractWorkflow.java:606)
at com.atlassian.jira.workflow.OSWorkflowManager.createIssue(OSWorkflowManager.java:754)
... 363 more
2020-10-01 07:04:00,432 ERROR [workflow.AbstractScriptWorkflowFunction]: Workflow script has failed on issue UFC-25633 for user 'sysadmin'. View here: https://support.test.uniface.com/secure/admin/workflows/ViewWorkflowTransition.jspa?workflowMode=live&workflowName=Uniface+Issue+Jira+Service+Desk+IT+Support+Workflow+-+V0.2&descriptorTab=postfunctions&workflowTransition=41&highlight=1
java.lang.NullPointerException: Cannot get property 'id' on null object
at com.onresolve.scriptrunner.canned.jira.workflow.postfunctions.CloneIssue.execute(CloneIssue.groovy:164)
at com.onresolve.scriptrunner.canned.jira.workflow.postfunctions.CloneIssue$execute$0.callCurrent(Unknown Source)
---

Gustavo Félix
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.
Oct 01, 2020

What kind of custom fields are your fields ? TextFields or Select List? 

Organizations is a custom field provided by JSD of type Organizations (select list, multiple choice)

Reported Organization is of type Text field (single line)

Although several Organizations are possible, in practice 1 will always be chosen.

Schermafbeelding 2020-10-01 om 10.07.30.png

Gustavo Félix
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.
Oct 01, 2020

Ok, two things.
1) Caused by: com.atlassian.jira.workflow.WorkflowException: Error occurred while creating issue. This could be due to a plugin being incompatible with this version of JIRA. For more details please consult the logs, and see: http://confluence.atlassian.com/x/3McB

It seems that your version is not updated. I've never seen that error, but that webpage says that.  Maybe something you need to check out. 

2) I didnt read that you were using jira service desk, I thought it was Jira Server . So , I cant replicate the use of "Organizations". It seems from what I've searched, is a select list, but I'm not sure how to handle the field.

I would try 
def cfOrganization = customFieldManager.getCustomFieldObjects(sourceIssue).find {it.name == 'Organizations'} as List

Before the setCustomFieldValue , add a 
log.warn "cfOrganization.get(0)" 

Just to test if it logs something.

But again, I dont have JSD , so I'm almost guessing here.
My suspect is that you are trying to set an Organizations type field to a String field, so that has to be converted somewhere.

I hope this helps you.

Thanks @Gustavo Félix 

I changed the script again (and moved the post function below the re-index post function)

and now it works!

Like Gustavo Félix likes this

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events