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
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"
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 :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.