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, loom, loom for training, loom for teaching, video training, async learning, online education, screen recording, loom tutorials, loom use cases, atlassian learning, team training tools, instructional video, virtual training tools

🛗 Elevate Your Training and Enablement with Loom

Join us June 26, 11am PT for a webinar with Atlassian Champion Robert Hean & Loom’s Brittany Soinski. Hear tips, stories, and get your burning questions answered. Learn how Loom makes training and enablement easier. Don’t miss it!

Register today
AUG Leaders

Atlassian Community Events