How to display a custom field only for a particular transition and hide in rest of the transitions

i have a custom field "check box" when i create a issue. However i would want to display this on the "Issue View Page" if the transition name is "A" but when i move this issue to other transitions like "B","C" etc this field should be hidden . i did try it using the behavior but doesn't seem to be working. Can anyone please help me on this.

 

Untitled.png

 

i have even tried adding this server side script on the behavior plugin for the custom field

import com.atlassian.jira.ComponentManager;
import org.apache.log4j.Category;
import com.atlassian.jira.workflow.JiraWorkflow
ComponentManager componentManager = ComponentManager.getInstance()
JiraWorkflow workflow = componentManager.getWorkflowManager().getWorkflow(issue);
def wfd = workflow.getDescriptor()
def actionName = wfd.getAction(transientVars["actionId"]).getName()
FormField SaveAsDraft= getFieldById ("customfield_14905")
String SaveValue = (String) SaveAsDraft.getFormValue()  
if(actionName != "Draft")
{
    SaveValue.setHidden(false)
  
}
else
{
SaveValue.setHidden(true)
}

3 answers

1 accepted

2 votes
Accepted answer

This seems a little confused to me.

First, there's no such thing as "view" on a transition.  A transition changes the status of an issue, and during a transition you can have a screen, but it's not a "view", it's an "edit"

So, there are two things I'm imagining you actually might mean:

  1. You do mean "transition": If you want a field to appear during transition A, but not transition B, then use two different screens
  2. You really mean you want to display the field depending on the status (not transition):  Change your behaviour script to look at status - the transition is irrelevant

Hi Nic..May be i wasn't clear much.i have attached a screenshot for the image above. There you can see a check box named "Save As Draft". i will explain the context below. The workflow has some states. Initial state is "draft" and then its "submit" state. Default behavior is whenever the issue is created it bypasses the "draft" state and issue is transitioned to the "submit" state. In case the user ticks the checkbox "Save As Draft" only then the issue is transitioned to "draft" state. But after this draft state when the issue further progresses to different state, the checkbox data "Save As Draft" : Yes , will always be displayed which is incorrect since the issue has moved out of the draft state. So i wanted to know how can we hide this after the draft state.

The best answer here is "delete the draft field and educate your users to understand that they should look at the status" The next best option is to clear the checkbox on transition because the data is wrong. I'd put a post-function on the transitions out of "draft" to "not draft" status. Hiding it is the worst approach because you can still see it in reports, search for it and so-on. I'd just use the status correctly.

I agree with Nic... you don't have a "view issue screen for a transition". However from a cursory look at your code, you are trying to hide the field value, and not the field.

So you should use:

saveAsDraft.setHidden(true/false)

you don't need to get the form value at all.

Thanks Nic and Jamie for explaining it so clearly. I managed to do it "Clear custom field" postfunction which Nic explained.

 

 

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Nov 27, 2018 in Portfolio for Jira

Introducing a new planning experience in Portfolio for Jira (Server/DC)

In the past, Portfolio for Jira required a high degree of detail–foresight that was unrealistic for many businesses to   have–in   order to produce a reliable long-term roadmap. We're tur...

2,667 views 18 21
Read article

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