Forums

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

Script run as behavior but not as automation script

Guy Marelly July 18, 2022

Hi all, I run the below script as behavior script and it works. When trying to run the code from automation rules I get some errors:

 

int selectListId = 16700
def selectList = getFieldById("customfield_" + selectListId)

String issuetype = getIssueContext().getIssueType().getName()
def map

switch (issuetype) {
    case "Epic":
        map = ["S", "M"]
        break;

    case "Initiative":
        map = ["L", "XL", "XXL"]
        break;
}

if (map) {
    selectList.setFieldOptions(map)
}
The error I get:
[Static type checking] - Cannot find matching method Script1428#getFieldById(java.lang.String). Please check if the declared type is correct and if the method exists.
[Static type checking] - Cannot find matching method Script1428#getIssueContext(). Please check if the declared type is correct and if the method exists.
[Static type checking] - Cannot find matching method java.lang.Object#setFieldOptions(java.util.List <java.lang.String>). Please check if the declared type is correct and if the method exists.
Can you please assist how this issue can be resolved?

1 answer

1 accepted

0 votes
Answer accepted
Dirk Ronsmans
Community Champion
July 19, 2022

Hi @Guy Marelly ,

I'm afraid that's normal. A behaviour and a Job/Listener (which I assume you use as an automation) work differently.

A behaviour is based on the UI/Screen and has specific methods available such as getFieldById()

These methods don't work in a standalone script so you'll have to rewrite it to actually work in the job/listener context.

 

I suggest checking out the adaptavist documentation first https://docs.adaptavist.com/sr4js/latest/features/jobs

 

TLDR; behaviours use different methods than jobs/listener so you'll have to use the right ones.

Guy Marelly July 19, 2022

Thanks Dirk for your quick reply and explanation!

I'll check the documentation you've recommended.

Suggest an answer

Log in or Sign up to answer
TAGS
atlassian, jira product discovery, jpd premium, product management, idea management, product discovery, jira premium, product planning, atlassian community, product development, roadmap planning, product prioritization, feature management

Introducing Jira Product Discovery Premium ✨

Jira Product Discovery Premium is now available! Get more visibility, control, and support to build products at scale.

Learn more
AUG Leaders

Atlassian Community Events