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

Teja September 9, 2019

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.

2 answers

1 accepted

1 vote
Answer accepted
Ravi Sagar _Sparxsys_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 9, 2019

Hello @Teja 

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

Let me know.

Ravi

Teja September 9, 2019

Hi @Ravi Sagar _Sparxsys_ ,

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 

Teja September 9, 2019

@Ravi Sagar _Sparxsys_ 

I saw all your videos in YouTube :)

Liked it.

Like Ravi Sagar _Sparxsys_ likes this
Ravi Sagar _Sparxsys_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 9, 2019

Hi @Teja 

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

Teja September 9, 2019

Hi @Ravi Sagar _Sparxsys_

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

Teja September 11, 2019

Hi @Ravi Sagar _Sparxsys_ Any help?

Ravi Sagar _Sparxsys_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 12, 2019

Hi @Teja 

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 

Teja September 13, 2019

Hi @Ravi Sagar _Sparxsys_ 

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

Ravi Sagar _Sparxsys_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 13, 2019

What is the exact type of Sales Collateral field?

Teja September 13, 2019

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

Thanks

Ravi Sagar _Sparxsys_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 13, 2019

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

Teja September 13, 2019

Sorry my mistake.....

It working absolutely fine....

You're awesome....

Custom field name mismatch..

Thanks

Tejas

Like Ravi Sagar _Sparxsys_ likes this
Ravi Sagar _Sparxsys_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 13, 2019

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

Ravi Sagar _Sparxsys_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 13, 2019

Good to know. Have a nice day.

Like Teja likes this

Suggest an answer

Log in or Sign up to answer