Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Behavior that is running on create customer request submit

Margaret Boisvert February 15, 2021

I have behavior that is attached to a custom field (Client Type).  If the Client Type changes, I need to reset another custom field (State) to None so that the user has to pick it again.

This works fine while making changes to different fields on the form, but the behavior also runs when I submit the Create form and wipes out the other custom field so the form throws an error because the 2nd custom field is required and has been reset to None.

The value of the Client Type field did not change but the code is still running.  I have verified the through logging.

import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.component.ComponentAccessor
import org.apache.log4j.Level

log.debug("Running Client Type field code")

def ClientTypeField = getFieldById(getFieldChanged())
def selectedClientType = ClientTypeField.getValue().toString()
log.debug("Client Type = " + selectedClientType)

def stateField = getFieldByName("State")
stateField.setFormValue(null)

 

Why is the behavior running when I submit the form???

1 answer

Suggest an answer

Log in or Sign up to answer
0 votes
Ram Kumar Aravindakshan _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 22, 2021

Hi Margaret,

If you want to reset the second field every time the first field is updated, you could try something like this:

def optionsField = getFieldById(fieldChanged)//Options
def level = getFieldByName("Level")

if(optionsField) {
level.setFormValue("-1")
}

Please note, this sample code is not 100% exact to your environment. Hence, you will need to make the required modifications.

In this example, I am using both single-select list fields, i.e. for Options and Level. So, whenever the Options field is updated, the Level field will automatically reset to None.

For testing purposes, I also included other lists on my create screen and tested it to check if those fields will get reset by the Behaviour when I create the issue, and I don't seem to be facing the issue.

I hope this helps to solve your question :)

I am looking forward to your feedback.

Thank you and Kind Regards,

Ram

TAGS
AUG Leaders

Atlassian Community Events