Forums

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

Is it possible to hide a custom field

Lonn James Holiday
Contributor
May 2, 2019

Greetings,

I am new here and this is my first question!

I have completely stripped the adaptivist example https://scriptrunner.adaptavist.com/5.4.47/jira/behaviours-overview.html down to

 

log.info "hide script start"

 

def hiddenCf = getFieldById("ActHidden")

log.info ("definitions complete")

 

    hiddenCf.setHidden(true)

 

log.info "hide script ran"

 

And it returned:

2019-05-01 21:49:27,892 http-nio-8080-exec-18 INFO marie 1309x36109x1 1coeg1v 71.212.40.101,0:0:0:0:0:0:0:1 /rest/scriptrunner/behaviours/latest/runvalidator.json [c.o.j.groovy.user.FieldBehaviours] hide script start

2019-05-01 21:49:27,892 http-nio-8080-exec-18 INFO marie 1309x36109x1 1coeg1v 71.212.40.101,0:0:0:0:0:0:0:1 /rest/scriptrunner/behaviours/latest/runvalidator.json [c.o.j.groovy.user.FieldBehaviours] definitions complete

2019-05-01 21:49:27,892 http-nio-8080-exec-18 INFO marie 1309x36109x1 1coeg1v 71.212.40.101,0:0:0:0:0:0:0:1 /rest/scriptrunner/behaviours/latest/runvalidator.json [c.o.j.groovy.user.FieldBehaviours] hide script ran

2019-05-01 21:49:27,893 http-nio-8080-exec-18 DEBUG marie 1309x36109x1 1coeg1v 71.212.40.101,0:0:0:0:0:0:0:1 /rest/scriptrunner/behaviours/latest/runvalidator.json [c.o.jira.behaviours.BehaviourManagerImpl] Returning map: [ActHidden:[hidden:true]]

 

So, the script runs. It sets the value. Jira does not hide the field despite the fact it is set ActHidden:[hidden:true].

Am I missing something simple?

 

Thanks,

Lonn

 

2 answers

0 votes
Elifcan Cakmak
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.
May 3, 2019

Hello,

getFieldById, as the name suggests, work with the customfield id. So you need to write something like

def hiddenCf = getFieldById("customfield_19000")

You can get this id by hovering on "edit" button at the customfield,  on customfields page. After that it should work.

Regards.

Lonn James Holiday
Contributor
May 3, 2019

Thanks, Elifcan,

That's a great technique to use going forward for things like that. In this case, getFieldByName("ActHidden") is more appropriate since "ActHidden" is my custom field name.

Thanks,

Lonn

Elifcan Cakmak
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.
May 3, 2019

Hi, 

I recommend you use the ID, though, because if someday you decide to change the custom field's name, then your script and any other script that uses that custom field will stop working. That's why I always use custom field ID. Just wanted to remind you that :) 

Regards.

Lonn James Holiday
Contributor
May 4, 2019

That makes total sense. Thanks.

0 votes
Andreas Lorz
Contributor
May 3, 2019

'def hiddenCf = getFieldById("ActHidden")'

you wrote 'ActHidden' as an example? If not you have to either use getFieldById("customfield_123456") or use getFieldByName("ActHidden")

also see: https://scriptrunner.adaptavist.com/5.4.47/jira/behaviours-api-quickref.html

Lonn James Holiday
Contributor
May 3, 2019

No, that is my field name. You are right. I should use getFieldByName("ActHidden").

I'll report back if that makes any difference in the effectiveness of the script.

This has been sidelined for now but I think it would be cool to solve. It's a test snippet for a larger script intended to hide fields from specific users or groups.

Thanks for the link and the input,

Lonn

Suggest an answer

Log in or Sign up to answer