Problem Getting FormField by ID (returns null)

Shachar Ovadia July 2, 2021

Hi guys !

I'm trying to create a script with behaviour (server-side script),

but the problem for me is im getting null from getFieldById("fixVersions));

or either getFieldByName("Fix Version/s");

neither FormField instead of def fixVersions = getFieldById("fixVersions");

import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.project.version.Version
import com.onresolve.jira.groovy.user.FieldBehaviours
import com.onresolve.jira.groovy.user.FormField
import com.atlassian.jira.project.version.Version

Issue issue = event.issue;

Collection<Version> version = issue.getFixVersions();
def fixVersion = getFieldById("fixVersions");
//def values= fixVersion.getValue();

def values = fixVersion.getValue() as List<Version>

if(values == null || values == "" || !values){
fixVersion.clearError();
}

for(int ver = 0; ver < version.size(); ver++){
boolean isReleased = version[ver].isReleased();

if(isReleased){

fixVersion.setError("Cant Assign Issue To A Released Version !");

} else{
fixVersion.clearError();
 }
}

any help solving ?

Thank you!

1 answer

0 votes
Charlie Misonne
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 2, 2021

Hi Shachar, welcome to the Atlassian Communit!

Have you tried:

 getFieldById("fixVersions")

I had to look it up but that is used in the vendor's documentation on this page

Shachar Ovadia July 2, 2021

Hi Charlie, thanks for the reply, Yes i have tried even copying the documentation code, doesnt seem to catch the field event.

tried getFieldChanged aswell, same result.

affter adding a version, this is the result from the script runner logs :

---- Form field ID: fixVersions, value: null.

 

i have read the decomentation over and over haha.

Suggest an answer

Log in or Sign up to answer