Forums

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

problem on script subtack_copy_product.groovy

Florian PEREZ [Valiantys Administrator]
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.
July 7, 2020

Hi everyone,

I'm actually debugging an instance looking at the logs i find that one of the script on the instance generate most of my errors but i cant figure why ...

The error in the log look the same everytime :

2020-07-07 12:54:13,535 https-jsse-nio-8443-exec-206 ERROR afcaire 774x1732710x1 1n7aouf 10.33.117.20,10.33.97.14 /rest/scriptrunner/behaviours/latest/runvalidator.json [c.o.jira.behaviours.BehaviourManagerImpl] *************************************************************************************
2020-07-07 12:54:13,537 https-jsse-nio-8443-exec-206 ERROR user 774x1732710x1 1n7aouf 10.33.117.20,10.33.97.14 /rest/scriptrunner/behaviours/latest/runvalidator.json [c.o.jira.behaviours.BehaviourManagerImpl]

Script function failed on issue: (create issue) project/issuetype: SUPTOOL/Bug, user: user, fieldId: customfield_13575, file: subtack_copy_product.groovy

org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object 'null' with class 'null' to class 'long'. Try 'java.lang.Long' instead
at subtack_copy_product.run(subtack_copy_product.groovy:11)

So i find the script and i can't figure out what's going on. 

Here's the script: 

import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.MutableIssue

// 3 lines needed to use a groovy file for fieldbehavior
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript
@BaseScript FieldBehaviours fieldBehaviours

// Get all interesting fields
def type = getFieldById("issuetype").getValue()
def parentId = getFieldById("parentIssueId").getValue() as long
def product = getFieldByName("Product")


// If it is a sub-task, and product is not yet set
if (type == "10003" && product.getValue() == null) {

// Get the parent issue
MutableIssue parentIssue = ComponentAccessor.getIssueManager().getIssueObject(parentId)

//Get the value of the product field
def parentProduct = parentIssue.getCustomFieldValue(ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Product"))

// Set the product field to the same value as the parent
product.setFormValue(parentProduct.getOptionId())

}

I would appreciate à lot a bit on help on this one ! 

Thanks a lot ! 

Florian

1 answer

1 accepted

1 vote
Answer accepted
Nic Brough -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.
July 7, 2020

I'd expect this to fail if it is applied to issues that are not sub-task types.   These won't have a parentIssueID, so line 11 is coming back "null"

Florian PEREZ [Valiantys Administrator]
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.
July 7, 2020

Thx a lot. I think i just fix the problem by mooving the def in the if:

import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.MutableIssue

// 3 lines needed to use a groovy file for fieldbehavior
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript
@BaseScript FieldBehaviours fieldBehaviours

// Get all interesting fields
def type = getFieldById("issuetype").getValue()

def product = getFieldByName("Product")


// If it is a sub-task, and product is not yet set
if (type == "10003" && product.getValue() == null) {

//def parentId if the ticket is actually a sub task for avoiding null value
def parentId = getFieldById("parentIssueId").getValue() as long

// Get the parent issue
MutableIssue parentIssue = ComponentAccessor.getIssueManager().getIssueObject(parentId)

//Get the value of the product field
def parentProduct = parentIssue.getCustomFieldValue(ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Product"))

// Set the product field to the same value as the parent
product.setFormValue(parentProduct.getOptionId())

}

 It'll go in test tomorow  :)

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events