Forums

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

I am trying to set value to a field or trying to hide a field for my project but not working.

Pramod.Kumar.Ojha May 20, 2025

I am trying to set value to a field or trying to hide a field for my project using groovy script or by enabling readonly button in Behaviour. But not working.

Please help me to fix this.

image.pngimage.png

3 answers

0 votes
Piyush Annadate _ACE Pune_
Community Champion
May 20, 2025

Hello @Pramod.Kumar.Ojha ,

You may not require the component accessor line here. Can you check with below script  based on your requirement - If type is Race Subtask then readonly to duration and dclink field as hidden. 

def issueTypeField = getFieldById("issuetype")
def currentIssueType = issueTypeField.getValue()

// Fields to manipulate
def durationField = getFieldByName("Estimated Duration (w)")
def dcLinkField = getFieldByName("DataCenter Link")

if (currentIssueType == "Rack Sub-task") {
// Make duration field read-only
durationField.setReadOnly(true)

// Hide DataCenter Link field
dcLinkField.setHidden(true)

// Optionally set a default value
durationField.setFormValue("5")
} else {
// Reset to writable and visible if not "Rack Sub-task"
durationField.setReadOnly(false)
dcLinkField.setHidden(false)
}

 

Pramod.Kumar.Ojha May 20, 2025

image.png

Pramod.Kumar.Ojha May 20, 2025

not working.image.png

0 votes
Dilip
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
May 20, 2025

Hi @Pramod.Kumar.Ojha 

could you please try like this:

getFieldByName('DataCentre Link').setReadOnly(true)
Pramod.Kumar.Ojha May 20, 2025

Its not working.

I already have working code which is working in Staging environment. But same code is not working in production.

 

import com.atlassian.jira.component.ComponentAccessor

// Get the field to populate
def targetField = getFieldByName("DataCenter Link") // Replace with your field name
// Get parent issue ID from hidden field
def parentIdStr = getFieldById("parentIssueId")?.value?.toString()

if (parentIdStr && targetField) {
def issueManager = ComponentAccessor.issueManager
def parentIssue = issueManager.getIssueObject(parentIdStr.toLong())
log.warn"parentIssue:${parentIssue}"
if (parentIssue) {
// Now set the field with the actual parent issue key like "PROJ-123"
targetField.setFormValue(parentIssue.key)
}
}
image.png

 

Piyush Annadate _ACE Pune_
Community Champion
May 20, 2025

Any sort of error or something else you can share?

Pramod.Kumar.Ojha May 20, 2025

We are not getting any error.

Pramod.Kumar.Ojha May 20, 2025

I am able to set the field values of a different project on jira. But the issue is for specific project("IaaS DCPM"). Though we are not getting any error in behaviour but the value is not set on the field.

Do we require any specific permission to set the field value on DCPM project.

Thanks!

0 votes
Thuan_ Do Dang
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 20, 2025

Hi Pramod_Kumar_Ojha,

Do you need to exclude The "DataCenter Link" from your screen?
You can do it by many way

 - Create new screen for your sub-task and remove this field from your screen

 - Create a Field Configuration for your sub-task then hidden the field by Field Configuration

 - Set Custom Field context to exclude your issue type.

 - Set Hidden for this field only in the ScriptRunner Behaviour

Hope this helps!

Suggest an answer

Log in or Sign up to answer