Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Setting fields hidden in post function using scriptrunner

Johnathan Teo May 16, 2019

Hi,

I have looked around and have create a hide field and revel when something is chosen eg. When resolution is duplicate, the duplicate link will be revelled and set to mandatory.


What I want to do now is to do it on the workflow at the post function. Is this possible?

My code so far is

 

 

def issueManager = ComponentAccessor.getIssueManager()
def constantsManager = ComponentAccessor.getConstantsManager()
def resolution = constantsManager.resolutions.findByName("Resolved")
def fixVersion= issue.getFixVersions()


if ( resolution == "Resolved" )

{
fixVersion.setRequired(true)
fixVersion.setHidden(false)
}
else {
fixVersion.setRequired(false)
fixVersion.setHidden(true)
}

 

 

The errors I'm getting is attached. Meanwhile I'll still look for an answer. 

( I'm assuming is that my fixVersion is getting the value instead of the field? )error.png

1 answer

0 votes
Tarun Sapra
Community Champion
May 16, 2019

Hello @Johnathan Teo 

The code samples you have in the screenshot and the ability to hide/show fields and the API you have used are part of the "Behaviour" module of the Script runner plugin and not the post-function, using this in post-funciton will not work.

https://scriptrunner.adaptavist.com/5.4.47/jira/behaviours-overview.html

Tarun Sapra
Community Champion
May 16, 2019

Here's where you can have the behaviour available for customizations

https://scriptrunner.adaptavist.com/5.4.47/jira/behaviours-overview.html#_screens

Johnathan Teo May 16, 2019

Ah, I see. Is there a way to actually do it in post function instead of in behaviours ?

As there is another condition that the status must be moving to closed before this will trigger. 

As there are many links made to close, it is hard for me to check by status. So I was thinking of putting the code on the transition when it moves to close. 

So what will happen is when a user transition to close, there is a pop up screen asking them to choose their resolution. When they choose "Resolved" the Fix Version field should pop up and be made mandatory. 

Tarun Sapra
Community Champion
May 16, 2019

Hello @Johnathan Teo 

Having the code in the post-function is not possible but it's best to have it as part of the transition screen. So  that resolution is not set you can set "error" on the fixVersion and when resolution is set you can then "clearError" using setError method from API will prevent the user from submitting the transition screen and hence no need to extra validation as well.

https://scriptrunner.adaptavist.com/5.4.47/jira/behaviours-api-quickref.html#_formfield_seterror_errorstr

If my answer, helped you then please accept/upvote the answer so that other users are also helped. thanks.

Suggest an answer

Log in or Sign up to answer