Forums

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

Scripted Custom Field update with Condition

Tamil July 3, 2020

Hi,

I  have defined a scripted field "ID" which sets issuekey value to this field "ID" which works fine.

I am migrating project issues(CSV import) into jira where some of the issues has values of ID present already. But after import these values are overwritten with issuekey value.

I have set a IF condition to define only if (id==null) set issue key value to ID. But after project import the ID values are still overwriting.

I have below clarifications

1) If a field is scripted field, the project import values to that field will be overwritten always?

2) If yes then what is the way to define a condition that after project import my condition executes. The current script is in Scriprunner Scripted Fields. 

where do i define script to allow project import values of ID without overwriting by Scripted Field condition?

 

 

import com.atlassian.jira.issue.Issue
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager

CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()

def cf = customFieldManager.getCustomFieldObject('customfield_10308')
def id_value=issue.getCustomFieldValue(cf)
//return id_value

if(id_value==null)
{
def key=issue.getKey()

def slash = key.toString()
def id1=slash.replaceAll("[-]",'')


return id1
}else{
return id_value
}

 

1 answer

1 accepted

1 vote
Answer accepted
Nic Brough -Adaptavist-
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.
July 3, 2020

Scripted fields do not contain any data.  They calculate and display it.

So the data you imported is irrelevant - there's nowhere to store it, so it is discarded.  Next time the issue is indexed, the display will be recalculated by the script.  (It's a bit more complex than "when indexed" in reality, but that is the easiest way to think of it)

To get your import to keep your old data, import the values into a standard custom field.  You can leave that off every screen if you want, so it doesn't bother the users.

Then change the scripted field so that the script reads the imported field, or calculates a new value as needed.

Tamil July 3, 2020

Hi Nic,

Instead of creating 2 fields(Normal field and scripted Field) Is it possible to place script in Behaviour or Listener so that after import if value is present it returns as it is and if not it will return issue-key value. 

For newly created issue after project import in jira, the field ID will have Issue-key. The problem is with existing data in project import.

Nic Brough -Adaptavist-
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.
July 4, 2020

No.  Think about when the script would run.  How would it know what to do at the point at which it runs?

Tamil July 4, 2020

@Nic Brough -Adaptavist- 

I created a normal custom field for importing data and Scripted field will check for condition to generate new one. This worked.

Thanks for the response!

Suggest an answer

Log in or Sign up to answer