Forums

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

How to set Priority based on custom fields in behavior?

Sander Spoelstra January 20, 2019

The question is pretty straightforward: I would like to automatically set the (default) priority field of an issue based on custom impact and urgency fields that have been configured (both are single choice select lists). The code shouldn't be too hard, but I can't get it to work. 

 

I've inserted the script beneath both as initialiser and on field level for priority, impact and urgency (mainly because I"m unsure which one to choose), but nothing seems to work.

So my question is twofold: 

  • Why isn't this script working?
  • Where should I set the script?

 

def AxDelImp = getFieldByName("Axon Delivery - Impact")
def AxDelUrg = getFieldByName("Axon Delivery - Urgency")
def prio = getFieldById("Priority")

if (AxDelImp.getValue() == "All users affected" && AxDelUrg.getValue() == "Complete outage")
{
prio.setFormValue("Prio 1")
}

 

1 answer

1 accepted

0 votes
Answer accepted
Tuncay Senturk _Snapbytes_
Community Champion
January 20, 2019

Hello Sander,

If you want to get Priority field by id, you should use lowercase priority.

def prio = getFieldById("priority")

That should do the trick

Sander Spoelstra January 20, 2019

Thanks for the help @Tuncay Senturk _Snapbytes_ It still doesn't seem to work though:

2019-01-21 07:22:56,048 ERROR [workflow.ScriptWorkflowFunction]: *************************************************************************************
2019-01-21 07:22:56,054 ERROR [workflow.ScriptWorkflowFunction]: Script function failed on issue: null, actionId: 1, file: <inline script>
groovy.lang.MissingMethodException: No signature of method: org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.getFieldByName() is applicable for argument types: (java.lang.String) values: [Axon Delivery - Impact]
 at Script10.run(Script10.groovy:1)

 I've been trying to get it to read the getValue as strings, but that doens't seem to solve the problem.

Why is the definition of my first field wrong?

Suggest an answer

Log in or Sign up to answer