Forums

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

Scriptrunner Scripted field server to cloud migration script (subtask inherits parent field value)

Duane Cronkite
Contributor
March 13, 2025

To no surprise, all of our scripted field scripts are broken in our test migration to the cloud.

I tried to use chatgpt etc to guide me into code fixes (I am not a developer) and can't seem to get anything to work. 

 

Original code working in server:

 

//
// Returns the value of the "FIELD" field from a
// subtask's parent issue.
//

import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.component.ComponentAccessor;

if (issue.isSubTask())
{
    def field = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("FIELD");

    if (field != null)
    {
        return issue.getParentObject().getCustomFieldValue(field);
    }
}

return null;
thanks in advance for any help!

3 answers

1 accepted

Suggest an answer

Log in or Sign up to answer
1 vote
Answer accepted
Duane Cronkite
Contributor
March 20, 2025

My pain your gain.

My team was able to figure it out

def hapiIssue = Issues.getByKey(issue.key as String)
def parentIssue = hapiIssue.getParentObject()
// Ensure the issue is a subtask
if (!parentIssue) {
    return "No parent issue found"
}

// Get the parent issue key
def parentIssueKey = parentIssue.getKey()

// getCustomFieldValue for a "text field single line" field will return an object of class java.lang.String (can use variable directly)
def customfield  = (String) parentIssue.getCustomFieldValue("ENTER PARENT FIELD HERE")

if (!customfield) {
    return "No 'custom field' set on parent issue"
}

return customfield
1 vote
Charlotte Santos -Appfire-
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.
March 14, 2025

Hi @Duane Cronkite 

I’m Charlotte, a support engineer at Appfire and I’m here to suggest an alternative.

If you don’t want to have to modify all the scripts, or to spend you Jira automation limit on this, and have an app like Jira Misc Workflow Extensions (JMWE) installed, you can use the feature called Event-based Actions to build this automation in a more user friendly way.

For example, in this feature you can create an automation that will copy any field value you want from the parent to the subtasks.

In your case, I recommend using the Copy issue field post function:

Screenshot 2025-03-14 at 13.55.08.png

Then, you just need to configure it to use the parent issue as source, the current issue as destination, and select all the field you want to be copied from one to the other as soon as a subtask is created:

Screenshot 2025-03-14 at 13.57.01.png

Please contact our support if you have any other questions about this feature, or JMWE in general.

We’ll be happy to help you! 😉

0 votes
Trudy Claspill
Community Champion
March 13, 2025

Hello @Duane Cronkite 

I am not an expert at scripting (for Scriptrunner), but I wanted to point out resources provided by Adaptavist in case you missed them.

Rewriting Scripts for Cloud Hints and Tips 

Example Scripted Fields 

Help from the community it free, of course, but if you have a lot of scripts that need rewriting you could also look at engaging Adaptavist or an Atlassian Solution Partner to help with rewriting scripts. (Disclosure: I work for Praecipio, and we are an Atlassian Platinum Solution Partner.)

 

You may also find that there are alternate solutions to scripting, such as using Automation Rules instead. Of course, there is not full overlap in functionality, but you may find some overlap that is useful. For example, in the above case you could create a normal custom field and use an Automation rule to copy data to it from the subtask's parent.

DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
PREMIUM
PERMISSIONS LEVEL
Product Admin
TAGS
AUG Leaders

Atlassian Community Events