Forums

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

Unable to clear Asset referenced custom field

Anusha Wilson March 12, 2025

I have a Asset and a Asset referenced field in a screen. The Asset referenced field lists values based on the Asset field. I am trying to clear the Asset referenced field whenever the Asset field is changed, so that users can select values for the Asset referenced field. I used the below behaviour script. But the value doesnt get cleared. Any help on this is appreciated. Thanks!

 

def category = getFieldById("customfield_27000");
def subcategory = getFieldById("customfield_27002");
def selectedCategory = category.getValue();

def myField = ComponentAccessor.getCustomFieldManager().getCustomFieldObjects().findByName("Category_A")
def fieldValue = underlyingIssue?.getCustomFieldValue(myField).toString()
def is_retained = fieldValue.contains(selectedCategory.toString())
if(fieldScreen.name.toString().contains("Edit"))
{
if(!is_retained)
{
    subcategory.setFormValue("")
  
}
}

1 answer

0 votes
Fabio Racobaldo _Catworkx_
Community Champion
July 17, 2025

Hi @Anusha Wilson ,

in my opinion the probel is related to .getCustomFieldObjects().findByName() method. It should return a list of custom fields.Please try the follwoing code :

 

import com.atlassian.jira.issue.CustomFieldManager;

import com.atlassian.jira.issue.fields.CustomField;

def category = getFieldById("customfield_27000");

def subcategory = getFieldById("customfield_27002");

def selectedCategory = category.getValue();

CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager();

CustomField myField = customFieldManager.getCustomFieldObjectByName("Category_A");

def fieldValue = underlyingIssue!=null?underlyingIssue.getCustomFieldValue(myField).toString():null;

def is_retained = (fieldValue!=null && fieldValue.contains(selectedCategory.toString()))?true:false;

if(fieldScreen.name.toString().contains("Edit")){

if(!is_retained){

    subcategory.setFormValue("")

  

}

}

 

Let me know,

Fabio

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events