How to Clear the Custom Field Value

Fazul February 13, 2019

Hi, 

I need to have the custom fields to be empty when I am closing the issue so that while closing the issue I can update the latest values in that custom field. The custom field is Text single line type.  I tried below code in validators, but getting an error. Kindly help.

 

import com.atlassian.jira.component.ComponentAccessor

def cf = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Ground")
issue.setCustomFieldValue(cf, null)

 

Jira Version - 7.6 ji.jpg

2 answers

2 accepted

1 vote
Answer accepted
Marc Minten _EVS_
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.
February 13, 2019

Hi, this is just static type checking, it is not a (blocking) error.It just says it does (can) not know the type of your cf variable (as you defined it by "def") and the null parameter. Nothing to worry about.

Save and your script will run (correctly).

Fazul February 13, 2019

I saved the script in validators and then published the workflow.

But when I moved  the issue  to the other transition, this filed is showing the previous valve only, and I tried to modify it, but still, it's showing as "Fill Grounding Box"

 

My need is, whatever the value given earlier should get cleared when I click Maintenance Complete step, and I need to give a new valve in the transition window.

image.pngimage.png

Marc Minten _EVS_
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.
February 13, 2019

Ok, I understand (I think :-))

First of all : changing (custom field) values in a "Validator" script does not make sense.

Second : You need the field to be cleared before the screen is shown, Validators are executed after the screen is updated by the user. But again, you cannot change custom field values in Validators!

Solution : you should clear the field in a Behaviors script (at screen initialization) and limit that to the specific workflow transition. See Behaviors documentation in Scriptrunner.

Like Döndü Türkmen likes this
neeta jain September 22, 2020

As the solution mentioned, can you please share some details how to clear the field in a behavior script.

Marc Minten _EVS_
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.
September 22, 2020

For a field named "MyField" :

import com.onresolve.jira.groovy.user.FormField

FormField fldMyField = getFieldByName("MyField")
fldMyField.setFormValue(null)

 

Like # people like this
0 votes
Answer accepted
Mihai Schwarz
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.
February 13, 2019

Use a post function in the transition to clear the field :)

Fazul February 13, 2019

Yes i had used a post function in the previous transition and then it cleared the field when im in the current screen. But i needed to get the field cleared when i click maintanence complete from the current screen. 

Mihai Schwarz
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.
February 13, 2019

So if I understood correctly you need to empty a field before you close it. So... Try to make an auto transition to clear the field after you move it to the last status before closed.


Example if you have the statuses In Progress -(Ready)> Ready For UAT -> Closed make an auto transition that will go from Ready to UAT in Ready to UAT when you press the Ready button(transition).

steven.mccaffrey February 18, 2020

@Mihai Schwarz
Not sure if you can help or understand why this happens but I want to simply clear a field prior to the transition screen. The odd issue is that in my UAT JIRA works perfectly and with a post-function it clears it up but in the PROD instance it waits till after. Both are the exact same Project, transition, clearing method and ranking in the the post-function(1st). 

Mihai Schwarz
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.
February 18, 2020

@steven.mccaffrey- First check if you have edit permissions and also check the screens of the issue, if they match especially the edit screen.

steven.mccaffrey February 18, 2020

@Mihai Schwarz 

I have edit rights because the clear action does happen just after the transition screen not prior like in my UAT. I compared the edit screens and they also are the same. I even re-indexed just to make sure as well. 

Mihai Schwarz
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.
February 19, 2020

@steven.mccaffrey- in your UAT env do you have a transition screen as well? As from my understanding is that in your UAT the transition and the post-fuctions works right away and in your production environment a transition screen pops up, am I right? If yes, you just have to eliminate the transition screen and it will behave the same.

steven.mccaffrey February 19, 2020

Yeah but no both UAT and PROD are set up the exact same for some reason one triggers the post function prior to the transition screen and the other triggers the post function after the transition screen. 
I'm honestly no sure which one is normal but what I just need my PROD Jira is to clear a custom field on the transition screen when that transition occurs. 
Any ideas?

Suggest an answer

Log in or Sign up to answer