Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

pot-function --> ERROR - Cannot invoke method startsWith() on null object

Eduard Diez
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.
October 4, 2018

Hi Community,

I've been struggling this problem for 3 days.

When I put the same code in console ScriptRunner the code it works ok but when I move it I have more problems, but I have 2 problems.

The method startsWith() -->but I don't work whit it

ERROR - Cannot invoke method startsWith() on null object

and I have ote rerror when I change 

Here is my source code :

////////////////////////nuevo codigo 04/10/2018
def transitionId = '61' //transicion (Finalizar desarrollo) DEMANDA a [Entregada]
def issueKey = issue.key
/*------------------EDU--------------------*/

def result = get('/rest/api/2/issue/' + issueKey)
.header('Content-Type', 'application/json')
.asObject(Map)
if (result.status >= 200 && result.status < 300){
logger.info('ok return')
} else {
return "Failed to find issue: Status: ${result.status} ${result.body}"
}
////////////////////////nuevo codigo 01/10/2018
/*------------------EDU--------------------*/
def link = result.body.fields.issuelinks //Busco todos los issuelinks de la DEM para saber el tipo de issue que cuelga de él
def num_issue = result.body.fields.issuelinks.size() //numero de tareas que cuelgan de la DEM
logger.info('links: '+num_issue)
for(def x = 0; x < num_issue; x++){
logger.info('entra en el for: '+x)
logger.info(link[x].inwardIssue)
preguntamos por los primeros estados del WF antes de hacer un movimiento
if (link[x]?.inwardIssue?.fields.issuetype.name == 'Historia' ||
link[x]?.inwardIssue?.fields.issuetype.id == '10300'){
if (link[x]?.inwardIssue?.fields.status.name == 'ENTREGADA (PTE. ACEPTACIÓN)' ){}
else return false
}
}

def resultTrans = post('/rest/api/2/issue/'+issueKey+'/transitions')
.header('accept', 'application/json')
.header('Content-Type', 'application/json')
.body('{\"transition\":{\"id\": \"'+transitionId+'\"}}')
.asJson()
if (resultTrans.status >= 200 && resultTrans.status < 300){
logger.info('transitionId='+transitionId)
return 'success y transitionId = ' + transitionId
} else {
return "Failed to find issue: Status: ${resultTrans.status} ${resultTrans.body}"
}
/*------------------EDU--------------------*/

2 answers

2 accepted

0 votes
Answer accepted
Eduard Diez
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.
October 5, 2018

Buenos dias @Daniel Yelamos [Adaptavist] me salen problemas de propiedades cuando se que están completos y los campos no son NULL ya que hago una consulta desde consola y es todo ok, pero al incluirlo a la post.funtion... no funciona... es un cagarro (esto no lo traduzco)

 

Captura.PNGCaptura2.PNG

 

Good morning Daniel I have still problems when they are complete since I make a query from console and it's all OK, but when I including it to the post.funtion ... it does not work ...

Eduard Diez
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.
October 5, 2018

Sorry @Daniel Yelamos [Adaptavist] My problem is [x] I solved 

Thank's for all

Daniel Yelamos [Adaptavist]
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.
October 5, 2018

Edu:

Have you used the modified script that I sent you?

Cheers

DY

Eduard Diez
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.
October 5, 2018

Yes, but I less, I put your code and it's fantastic.

Thank's for all

0 votes
Answer accepted
Daniel Yelamos [Adaptavist]
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.
October 4, 2018

Hola Edu! 

¿Como estamos? Te voy a echar una mano, pero te tengo que responder en ingles para que el resto de mi equipo pueda leer esta respuesta. ¿Va?

I've modified your code according to the following:

1. In groovy instead of for looping you can use a .each closure. Your 'link[x]' has been renamed to 'it'. You can read more about .each closures here.

2. I've modified 'link'(singular) to 'links'(plural) for better clarity.

3. I've changed the empty if clause by negating the equals and returning false in the if, rather than in the else.

4. I've propagated the '?' use to everything on your statements, as when you use '?' you are accepting that anything that follows that '?' can also be null.

////////////////////////nuevo codigo 04/10/2018
def transitionId = '61' //transicion (Finalizar desarrollo) DEMANDA a [Entregada]
def issueKey = issue.key
/*------------------EDU--------------------*/

def result = get('/rest/api/2/issue/' + issueKey)
.header('Content-Type', 'application/json')
.asObject(Map)
if (result.status >= 200 && result.status < 300) {
logger.info('ok return')
} else {
return "Failed to find issue: Status: ${result.status} ${result.body}"
}
////////////////////////nuevo codigo 01/10/2018
/*------------------EDU--------------------*/
def links = result.body.fields.issuelinks //Busco todos los issuelinks de la DEM para saber el tipo de issue que cuelga de él
def num_issue = result.body.fields.issuelinks.size() //numero de tareas que cuelgan de la DEM
logger.info('links: ' + num_issue)
links.each {
logger.info('entra en el for: ' + it)
logger.info(it.inwardIssue)
//preguntamos por los primeros estados del WF antes de hacer un movimiento
if (it.inwardIssue?.fields?.issuetype?.name == 'Historia' ||
it.inwardIssue?.fields?.issuetype?.id == '10300') {
if (it.inwardIssue?.fields?.status?.name != 'ENTREGADA (PTE. ACEPTACIÓN)') {
return false
}
}
}

def resultTrans = post('/rest/api/2/issue/' + issueKey + '/transitions')
.header('accept', 'application/json')
.header('Content-Type', 'application/json')
.body('{\"transition\":{\"id\": \"' + transitionId + '\"}}')
.asJson()
if (resultTrans.status >= 200 && resultTrans.status < 300) {
logger.info('transitionId=' + transitionId)
return 'success y transitionId = ' + transitionId
} else {
return "Failed to find issue: Status: ${resultTrans.status} ${resultTrans.body}"
}
/*------------------EDU--------------------*/

 Now, from this point. I don't know where the exception is getting thrown. However, I'm about 90% sure that it came from the for loop that I have now changed. Check if this code works and if it doesn't, when you get an exception, send me the precise and exact stacktrace and I'll take it from there.

Un saludo!

Dani

Eduard Diez
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.
October 4, 2018

muchas gracias @Daniel Yelamos [Adaptavist] voy a probarlo y te cuento 

 

Thank's Daniel I'm trying and tomorrow I'll tell you how I'm gone.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events