How to make a hidden customfield dependent on another customfield?

Hi,

I have two customfields of same type and same options, but one of them is hidden in all screens.

Now if a non-hidden customfield's option is selected, the hidden field should also be set with its respective option.

Thanks,

Bharadwaj Jannu

5 answers

1 accepted

I got the solution by creating a new customfieldtype which extends MultiSelectCFType(required for our customfield).

In that I overrode getVelocityParameters method with the required things.

If you want the field to change without a workflow transition or client side JS, using Event listeners is the only remaining option I can think of.

https://confluence.atlassian.com/display/JIRA/Listeners

You can configure it to listen for the Issue Updated event and take whatever action you wanrt.

You may not be able to change the value of a hidden field, but if it is possible the JIRA Behaviors Plugin is the way to do it.

https://marketplace.atlassian.com/plugins/com.onresolve.jira.plugin.Behaviours

if the field are select list then you can try with following code

<script type="text/javascript">  
jQuery(document).ready(function($) {
JIRA.bind(JIRA.Events.NEW_CONTENT_ADDED, function (e,context) {
		setFieldValue();
	});
		setFieldValue();
function setFieldValue(){	
		setValue();
		//showing field
	$('#customfield_13816').change(function() {
		setValue();
	});
}
function setValue(){
var parentFieldValue=$("#customfield_13816 option:selected").text();
//hidden field
$("#customfield_13817 option").each(function() {
  if($(this).text() == parentFieldValue) {
    $(this).attr('selected', 'selected');            
  }                        
});
}

});
</script>

add above script on second field description in field configuration

Hi rambanam,

Thanks for the answer, but using script make the browser compatible problems.

Is there any kind of functionality(like postfunction) which run exactly after a customfield is updated?

or by means of any plugin(like implementing cascade customfields) can we achieve this?

another option is by hiding custom field using JavaScript and then you can fill the field valu by using postfunction

You can write a post function to copy field A(available on scree) to field B(hidden).

Use the Copy Value From Other Field Post function which is part of JIRA Suites

Hi Chaitra, thanks for the reply

But using workflow postfunction, the functionality will not work for edit operation?

Dont have the Edit Operation. (this can be controlled by permission)

In Your Workflow have Edit tranistion at all the status & at this tranistion use the post function & this should work.

I didn't get you exactly.

My thinking is that though we write or use a workflow postfunction, it is going to work on creating or transitioning a issue only and it is not going to work on editing an issue. If not, please correct me.

You are correct - you can't do post-functions on Edit.

This is why Chaithra said "don't have the edit operation". You remove the edit permission from the project, and create transitions in the workflow called "edit" which go back to the current status.

You can only have post function at Workflow transtion & not on the updates of customfield.

Other options are,

  1. Use JAVA Scripts for copying the contents of the customfield.
  2. Have a servlet & in the Servelt copy the contents, call on the servlet must happen based on the update on the required customfield.
  3. Listners can be used

But I personnally feel Workflow is much easier.

Thanks Nic,

I got little idea on this. But rather moving to workflow changes, is there any kind of post functionality executed immediately after the customfield is checked/selected and before the update button is pressed on edit screen?

If at all exists, please help in that concern.

I feel like we're repeating ourselves here. We both keep telling you there are no post-functions on Edit. Then you ask the same question again.

Please re-read Chaithra's detailed answers again, mine are just "there are no post-functions on Edit", and Chaithra gives you the options I'd suggest already

Hi @Nic @Chaitra

I try to use listener approach.

For issue creation: ISSUE_CREATED

For issue updation: ISSUE_UPDATED event types exist.

Now the ISSUE_UPDATED event is generated for updations using issue panels also.But is there any event specific to issues updating from edit screen itself?

Issue updated is the event fired from edit. When you say "generated for updates using issue panels", what's actually happening is the system is using "Edit", but not going through the screen. It's the same process, but with only one field.

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Julia Dillon
Posted Tuesday in Jira

Tell us how your team runs on Jira!

Hey Atlassian Community! Today we are launching a bunch of customer stories about the amazing work teams, like Dropbox and Twilio, are doing with Jira. You can check out the stories here. The thi...

207 views 1 18
Join discussion

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you