Forums

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

Groovy: how to clean a field

Ivan D January 8, 2023

Hello,

I'm using Run a Script action in Jira automation to clean a checkbox field (Deviniti [Dynamic Forms] - Dynamic Checkboxes). The code is (maybe excessive):

import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.Issue

def field = ComponentAccessor.getCustomFieldManager().getCustomFieldObject("Checkbox")
issue.setFieldValue(field, null)

def customField = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Checkbox")
issue.setCustomFieldValue(customField, null)

Both issue.set.... show the similar error:

Static type checking - cannot find matching method com.atlassian.jira.issue.Issue#setCustomFieldValue or #setFieldValue

Please advise.

BR

1 answer

1 vote
Florian Bonniec
Community Champion
January 9, 2023

Hi @Ivan D 

 

Why a you using a script in automation for JIRA when you could use a rule that just edit the field ? If you edit a field but set no value it will clear it, no need to use a script.

 

Regarding the script

"setFieldValue" is use in Behaviours only

"getCustomFieldObjectByName" is deprecated

 

Regards

Ivan D January 9, 2023

Hi Florian,

 

Thank you for the feedback.

I cannot use Edit issue action because it doesn't see the field (not available to choose)

I'd use Additional fields there but I cannot figure out how to create correct JSON expression (question here)

 

BR

Suggest an answer

Log in or Sign up to answer