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

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

problem on script subtack_copy_product.groovy

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

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  :)

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Marketplace Apps & Integrations

Bitbucket Smart Commits vs. Genius Commits - What's the difference?

If you already heard about Smart Commits in Bitbucket, know that you just stumbled upon something even better (and smarter!): Genius Commits by Better DevOps Automation for Jira Data Center (+ Server...

114 views 0 2
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you