It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

How to make read-only field based two custom fields values are empty using behavior? Edited

Hi,

I have three custom fields,

1. Multi select list (Sales Collateral)

2. Multi user picker (Sales Collateral Owner)

3. Single Checkbox (Sales Collateral Completed)

I wanted to make 'Sales Completed' (checkbox) ready-only, when 'Sales' and 'Sales Owner' fields are empty. vice versa.

Thanks in advance.

1 answer

1 accepted

1 vote
Answer accepted

Hello @Tejas Naik 

Take a look at this example here. It will probably give you good idea on how to achieve this.

Let me know.

Ravi

Hi @Ravi Sagar -Adaptavist- ,

Thanks for your reply on this,

I have tried-

In behavior I added 'Sales Collateral Owner/s' field and I put 'server-side script'

sales.PNG

added 'Sales Collateral' field and I put 'server-side script'

sales1.PNG

It works when 'Sales Collateral Owner/s' is not empty and 'Sales Collateral' is empty.

It works when 'Sales Collateral' is not empty and 'Sales Collateral Owner/s' is empty.

But I need it to work together. 'Sales Collateral Completed' enable when 'Sales Collateral' and 'Sales Collateral Owner/s' are not empty.

and I tried combine together and put it in the Initialiser not working anything.

Any help????

Thanks 

@Ravi Sagar -Adaptavist- 

I saw all your videos in YouTube :)

Liked it.

Like Ravi Sagar -Adaptavist- likes this

Hi @Tejas Naik 

That's really good so far. I think you are close. How did you combine the 2 conditions together? Share the code, let us see why it is not working.

Ravi

Hi @Ravi Sagar -Adaptavist-

Here is the code:-

import com.atlassian.jira.component.ComponentAccessor


def salescol = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Sales Collateral")
def salescolValue = underlyingIssue?.getCustomFieldValue(salescol)

def salescolown = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Sales Collateral Owner/s")
def salescolownValue = underlyingIssue?.getCustomFieldValue(salescolown)

def salescolcom = getFieldById("customfield_15814") //Sales Colateral Completed customfield_14602
if (salescolValue && salescolownValue){
salescolcom.setReadOnly(false);
}
else{
salescolcom.setReadOnly(true);
}

Thanks

Hi @Tejas Naik 

Try this.

Add both the fields with the following code respectively.

Sales Collateral

def salescolValue = getFieldById(getFieldChanged()).getValue()
def salescolOwnValue = getFieldByName("Sales Collateral Owner").getValue()
def salescolCom = getFieldByName("Sales Collateral Completed")

if ( !salescolValue.toString().contains("null") && salescolOwnValue) {

salescolCom.setReadOnly(false)

}
else {

salescolCom.setReadOnly(true)

}

Sales Collateral Owner

def salescolOwnValue = getFieldById(getFieldChanged()).getValue()
def salescolValue = getFieldByName("Sales Collateral").getValue()
def salescolCom = getFieldByName("Sales Collateral Completed")

if ( !salescolValue.toString().contains("null") && salescolOwnValue) {

salescolCom.setReadOnly(false)

}
else {

salescolCom.setReadOnly(true)

}

Few things to note here.

  • The multi select list will return a collection instead of a single value.
  • Your original approach could have worked if you added one more condition with slight modification to handle the collection returned by multi select list.
  • The change on both the fields needs to be tracked. 

Let me know if it works.

Ravi 

Hi @Ravi Sagar -Adaptavist- 

I tried above suggestion

It works when I first enter value in 'Multiselect' field i.e. Sales Collateral and Sales Collateral value second.

But it did not work when I first enter Sales Collateral Owner and Sales Collateral second.

salescol1.PNG

salescol2.PNG

Anything wrong?

Thanks

What is the exact type of Sales Collateral field?

Sales Collateral -> Select List (multiple choices) -> Enabled dark feature "multiselect.frother.renderer" 

Thanks

I enabled the dark feature and the behaviour still works for me. So not sure why it is not working for you. 

Sorry my mistake.....

It working absolutely fine....

You're awesome....

Custom field name mismatch..

Thanks

Tejas

Like Ravi Sagar -Adaptavist- likes this

Your Sales Collateral field name is different. Change it in the code.

Good to know. Have a nice day.

Like Tejas Naik likes this

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted in Jira

Demo Den Ep. 7: New Jira Cloud Reports

Learn how to use two new reports for next-gen projects in Jira Cloud:  Cumulative flow diagram and Sprint burndown chart. Ivan Teong, Product Manager, Jira Software, demos the Cumulative ...

308 views 1 3
Join discussion

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you