The Atlassian Community Forums are currently in read-only mode. We will be relaunching on a new platform on September 22 (read more here). We apologize for the extended downtime. For concerns or questions, please email communitymanagers@atlassian.com. See you on the other side, on the new Atlassian Community Forums! :)

×

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

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

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.