scripting help - workflow

I am attempting to run a fairly simple script in a  workflow:

import static java.util.Calendar.YEAR; def year = new Date();  def priority = issue.getPriority().getString("name");
if(priority=="Critical"){ year = today + 365 } else if(priority=="Major"){ year = today + 730; } else if(priority=="Minor"){ year = today + 730; } else if(priority=="Trivial"){ year = today + 1095; } else { year = today; } return year.format('dd/MMM/yy');

 this was not working so I tried to run it as a "script" out of the workflow.

 

import static java.util.Calendar.YEAR import com.atlassian.jira.ComponentManager import com.atlassian.jira.issue.fields.CustomField import com.atlassian.jira.issue.CustomFieldManagerCustomFieldManager customFieldManager = componentManager.getCustomFieldManager()def componentManager = ComponentManager.getInstance() def issueLinkManager = componentManager.getIssueLinkManager() def date = new Date() def nextYear = new Date() def category = getCustomFieldValue("Supplier Category").valueif(category=="Critical"){  nextYear = date[YEAR] + 1 } else if(category=="Major"){  nextYear = date[YEAR] + 2 } else if(category=="Minor"){  nextYear = date[YEAR] + 2 } else if(category=="Trivial"){  nextYear = date[YEAR] + 3 } date.set(year: nextYear) date.format('dd/MMM/yy') setCustomFieldValue("Supplier Re-evaluation Date", date)

 

any idea what I am doing wrong?

 

3 answers

JIRA log error:

 

Caused by: groovy.lang.MissingMethodException: No signature of method: org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.getCustomFieldValue() is applicable for argument types: (java.lang.String) values: [Supplier Category]

0 vote

I think you've fed the getCustomFieldValue function the name of the field, rather than the field object it requires.

the way I read your reply, you are saying this I need to remove ".value"

 

import static java.util.Calendar.YEARimport com.atlassian.jira.ComponentManagerimport com.atlassian.jira.issue.fields.CustomFieldimport com.atlassian.jira.issue.CustomFieldManagerCustomFieldManager customFieldManager = componentManager.getCustomFieldManager()def componentManager = ComponentManager.getInstance()def issueLinkManager = componentManager.getIssueLinkManager()def date = new Date()def nextYear = new Date()def category = getCustomFieldValue("Supplier Category")if(category=="Critical"){ nextYear = date[YEAR] + 1} else if(category=="Major"){ nextYear = date[YEAR] + 2} else if(category=="Minor"){ nextYear = date[YEAR] + 2} else if(category=="Trivial"){ nextYear = date[YEAR] + 3}date.set(year: nextYear)date.format('dd/MMM/yy')setCustomFieldValue("Supplier Re-evaluation Date", date)

this does not work either, please let me know what an example might be so I can better understand the solution

 

I can't read your code here, but in the original post, you were giving a function that expects a *field* a *string*, which won't work.

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Julia Dillon
Posted Apr 17, 2018 in Jira

Tell us how your team runs on Jira!

Hey Atlassian Community! Today we are launching a bunch of customer stories about the amazing work teams, like Dropbox and Twilio, are doing with Jira. You can check out the stories here. The thi...

768 views 2 19
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