Need to make a custom field readonly after saving the form

Sema YILDIRIM December 8, 2019

Hi All,

 I have a form and there is a custom field called request type and this is a select list. Select list containes some values as [ test, project, defect]. if i save form as selecting defect from list this custom field supposed to be readOnly and shouldnt be updated.

I tried some code and managed to make field readonly,  But in edit mode when i change request type form test to defect without saving the form this filed become immediately readonly. I need to make it work  after saving the form.

if (getAction()?.id == 1)// Do not make field readonly on  Create mode
{
return
}

def CustomField_ = getFieldByName("Request Type")

def selectedOption = CustomField_.getValue() as String

def isOtherSelected = (selectedOption == "Defect" )

CustomField_.setReadOnly(isOtherSelected);

 

2 answers

0 votes
Thorsten Letschert _Decadis AG_
Marketplace Partner
Marketplace Partners provide apps and integrations available on the Atlassian Marketplace that extend the power of Atlassian products.
December 9, 2019

Hi @Sema YILDIRIM ,

an easy way to prevent users from editing certain fields is to

  • add this field to a transition screen only so it's only editable on executing a transition, e.g. the Create one
  • don't add/remove this field from the edit screen of your issue type so it can't be edited via the common Edit operation

Cheers
Thorsten

Sema YILDIRIM December 9, 2019

Hi @Thorsten Letschert _Decadis AG_ ,

where is it "Edit operation"? I can prevent it from being read only in the creat section. But how do I intervene in the edit section?

 

if (getAction()?.id == 1) // Do not run script on Create action
{
return
}

Thorsten Letschert _Decadis AG_
Marketplace Partner
Marketplace Partners provide apps and integrations available on the Atlassian Marketplace that extend the power of Atlassian products.
December 9, 2019

Hi @Sema YILDIRIM ,

sorry for having been too quick with my initial response. With regard to your use case, I've been successful in the past by adapting the solution provided by Joshua here: https://community.atlassian.com/t5/Jira-Service-Desk-questions/Can-t-hide-Comment-field-on-Edit-screen-using-methods-provided/qaq-p/676381

0 votes
Fadoua
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
December 8, 2019

@Sema YILDIRIM if no other fields need to be updated later then you have 2 options:

  • Either update the project permission if it is not shared, and grant the edit issue only to certain people.
  • Or add workflow properties (Be careful with this option as it may create problems for you if you try to do a Bulk Edit)

Best,

Fadoua

Suggest an answer

Log in or Sign up to answer