Script Runner Post Function Clone Issue

Hello!

 

I'm trying to create a clone issue in another project using script.
this is my script

cfValues['Derivar Tarefa']?.value == 'Incident'


def cf1 = customFieldManager.getCustomFieldObjects(sourceIssue).find {it.name == 'Catalogo de Servicios - LAM'}
issue.setCustomFieldValue(cf1, sourceIssue.getCustomFieldValue(cf1))
def cf2 = customFieldManager.getCustomFieldObjects(sourceIssue).find {it.name == 'Aplicación LAM'}
issue.setCustomFieldValue(cf2, sourceIssue.getCustomFieldValue(cf2))
def cf3 = customFieldManager.getCustomFieldObjects(sourceIssue).find {it.name == 'Servicio PIMS LAM'}
issue.setCustomFieldValue(cf3, sourceIssue.getCustomFieldValue(cf3))
def cf4 = customFieldManager.getCustomFieldObjects(sourceIssue).find {it.name == 'Servicio Policy Tool'}
issue.setCustomFieldValue(cf4, sourceIssue.getCustomFieldValue(cf4))
def cf5 = customFieldManager.getCustomFieldObjects(sourceIssue).find {it.name == 'Servicio GLI'}
issue.setCustomFieldValue(cf5, sourceIssue.getCustomFieldValue(cf5))
def cf6 = customFieldManager.getCustomFieldObjects(sourceIssue).find {it.name == 'Servicio LogViewer'}
issue.setCustomFieldValue(cf6, sourceIssue.getCustomFieldValue(cf6))
def cf7 = customFieldManager.getCustomFieldObjects(sourceIssue).find {it.name == 'Servicio Claim'}
issue.setCustomFieldValue(cf7, sourceIssue.getCustomFieldValue(cf7))
def cf8 = customFieldManager.getCustomFieldObjects(sourceIssue).find {it.name == 'Servicio Batch Module'}
issue.setCustomFieldValue(cf8, sourceIssue.getCustomFieldValue(cf8))
def cf9 = customFieldManager.getCustomFieldObjects(sourceIssue).find {it.name == 'Servicio PIMS Fixing'}
issue.setCustomFieldValue(cf9, sourceIssue.getCustomFieldValue(cf9))
def cf10 = customFieldManager.getCustomFieldObjects(sourceIssue).find {it.name == 'Servicio PIMS Person'}
issue.setCustomFieldValue(cf10, sourceIssue.getCustomFieldValue(cf10))
def cf11 = customFieldManager.getCustomFieldObjects(sourceIssue).find {it.name == 'Servicio PIMS Product'}
issue.setCustomFieldValue(cf11, sourceIssue.getCustomFieldValue(cf11))
def cf12 = customFieldManager.getCustomFieldObjects(sourceIssue).find {it.name == 'Servicio Interfaz'}
issue.setCustomFieldValue(cf12, sourceIssue.getCustomFieldValue(cf12))
def cf13 = customFieldManager.getCustomFieldObjects(sourceIssue).find {it.name == 'Servicio Vision'}
issue.setCustomFieldValue(cf13, sourceIssue.getCustomFieldValue(cf13))
def cf14 = customFieldManager.getCustomFieldObjects(sourceIssue).find {it.name == 'Servicio Report Vision'}
issue.setCustomFieldValue(cf14, sourceIssue.getCustomFieldValue(cf14))
def cf15 = customFieldManager.getCustomFieldObjects(sourceIssue).find {it.name == 'Servicio Sun System'}
issue.setCustomFieldValue(cf15, sourceIssue.getCustomFieldValue(cf15))
def cf16 = customFieldManager.getCustomFieldObjects(sourceIssue).find {it.name == 'Servicio Jenkins LAM'}
issue.setCustomFieldValue(cf16, sourceIssue.getCustomFieldValue(cf16))
def cf17 = customFieldManager.getCustomFieldObjects(sourceIssue).find {it.name == 'Servicio ODM LAM'}
issue.setCustomFieldValue(cf17, sourceIssue.getCustomFieldValue(cf17))
def cf18 = customFieldManager.getCustomFieldObjects(sourceIssue).find {it.name == 'Affects Version/s'}
issue.setCustomFieldValue(cf18, sourceIssue.getCustomFieldValue(cf18))
def cf19 = customFieldManager.getCustomFieldObjects(sourceIssue).find {it.name == 'Emergencia'}
issue.setCustomFieldValue(cf19, sourceIssue.getCustomFieldValue(cf19))
def cf20 = customFieldManager.getCustomFieldObjects(sourceIssue).find {it.name == 'Impacto'}
issue.setCustomFieldValue(cf20, sourceIssue.getCustomFieldValue(cf20))
def cf21 = customFieldManager.getCustomFieldObjects(sourceIssue).find {it.name == 'Ambiente LAM'}
issue.setCustomFieldValue(cf21, sourceIssue.getCustomFieldValue(cf21))
def cf22 = customFieldManager.getCustomFieldObjects(sourceIssue).find {it.name == 'Comportamento esperado'}
issue.setCustomFieldValue(cf22, sourceIssue.getCustomFieldValue(cf22))
def cf23 = customFieldManager.getCustomFieldObjects(sourceIssue).find {it.name == 'Comportamento com erro'}
issue.setCustomFieldValue(cf23, sourceIssue.getCustomFieldValue(cf23))
def cf24 = customFieldManager.getCustomFieldObjects(sourceIssue).find {it.name == 'Descrição passo-a-passo do erro'}
issue.setCustomFieldValue(cf24, sourceIssue.getCustomFieldValue(cf24))
def cf25 = customFieldManager.getCustomFieldObjects(sourceIssue).find {it.name == 'Tipo de Atendimento'}
issue.setCustomFieldValue(cf25, sourceIssue.getCustomFieldValue(cf25))


and i receive this message in log

 

2017-08-11 16:51:31,619 http-nio-8080-exec-29 ERROR b54037 1011x2651005x1 1rtofso 10.170.136.135,10.170.136.188 /secure/CommentAssignIssue.jspa [c.o.s.jira.workflow.ScriptWorkflowFunction] Script function failed on issue: ALSD-12, actionId: 501, file: null
java.lang.NullPointerException
    at com.atlassian.jira.issue.IssueImpl.getCustomFieldValue(IssueImpl.java:896)
    at com.atlassian.jira.issue.Issue$getCustomFieldValue$1.call(Unknown Source)
    at Script83.run(Script83.groovy:36)

 

 

 

pf1.PNGpf2.PNGpf3.PNG

1 answer

0 votes

Hello Valeria.

Those are a lot of customFields that you seem to be setting. Sadly for you, one of those is failing to give you the proper reference as you can see:

 "at com.atlassian.jira.issue.IssueImpl.getCustomFieldValue(IssueImpl.java:896)"

This means that one of the customFields that you are getting is null. Let me explain:

issue.setCustomFieldValue(cf1,sourceIssue.getCustomFieldValue(cf1))

In that line cf1 is null, because you have failed to properly get a reference to that object. That means that in one of your lines like this:

def cf10 = customFieldManager.getCustomFieldObjects(sourceIssue).find {it.name == 'Servicio PIMS Person'}

The "find" operation is returning null.

Do you understand what I mean?

You need to run each one of the lines "def cf" in the script console untill you see which one gives you null. Then you will know which line of your script you need to fix.

I hope this helps.

Cheers

DYelamos

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted Oct 11, 2018 in Marketplace Apps

You + one app + a desert island...

Hi all! My name is Miles and I work on the Marketplace team. We’re looking for better ways to recommend and suggest apps that are truly crowd favorites, so of course we wanted to poll the Community. ...

2,462 views 5 6
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