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: 
  • Community
  • Q&A
  • Jira
  • Questions
  • How to prevent the deletion of the required field value that is mapped using Behaviors plugin?

How to prevent the deletion of the required field value that is mapped using Behaviors plugin?

Chandu
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
June 5, 2020

Hi,

I have created 2 custom fields as below:

Custom Field 1 - Confidential Data? (Single select field)

Custom Field 2 - What kind of Confidential Data? (Text Field)

I have created the following code using Behaviours plugin (Adaptavist ScriptRunner) to make  'Custom field 2' required based on the value selected in the 'Custom Field 1' : 

 

def clientDataField = getFieldByName("What kind of Confidential data?")
def confidentialDataField = getFieldById(getFieldChanged())

def selectedOption = confidentialDataField.getValue() as String
def isOtherSelected = selectedOption == "Yes"

clientDataField.setHidden(!isOtherSelected)
clientDataField.setRequired(isOtherSelected)

The above script is working fine for the below scenario:

If 'Yes' is selected for the 'Confidential data?' field then 'What kind of Confidential data?' field should appear to be mandatory.

If 'No' is selected for the 'Confidential data?' field then 'What kind of Confidential data?' field is set to be optional and is hidden.

 

However, after creating the issue, I am able to delete the entire text  from the 'What kind of Confidential data' field even though the value 'yes' is chosen under 'Confidential Data?' field.

So, how to prevent users from deleting the text entered in 'Custom Field 2' after creating the issue? 

Note: I cannot remove the field from the edit screen because sometimes users might need to update the text in the 'What kind of Confidential data?' field. They should be able to edit the value but not delete it when 'Yes' is selected for 'Confidential Data?' field

Behaviours Code.JPG

0 answers

Comments for this post are closed

Community moderators have prevented the ability to post new answers.