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

This widget could not be displayed.

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.

This widget could not be displayed.

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.

This widget could not be displayed.

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
Posted Tuesday in Jira

What modern development practices are at the heart of how your team delivers software?

Hey Community mates! Claire here from the Software Product Marketing team. We all know software development changes rapidly, and it's often tough to keep up. But from our research, we've found the h...

264 views 1 3
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