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

Jayashree Shetty
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.
January 19, 2015

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
Answer accepted
Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 19, 2015

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
Jayashree Shetty
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.
January 20, 2015

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.

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 21, 2015

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.

Like prasenjit banik likes this
1 vote
JamieA
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.
January 21, 2015

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.

0 votes
Jayashree Shetty
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.
January 21, 2015

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