Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,557,772
Community Members
 
Community Events
184
Community Groups

Auto populate date field in subtask in Groovy Scripting

Edited

we need the "Need By date" field to auto populate while creation of subtask and its field value to be 5 days prior from the "Original due date" field value present in the parent task.  

1 answer

1 accepted

0 votes
Answer accepted
Peter-Dave Sheehan
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Nov 22, 2021 • edited

Are the subtasks created by some sort of existing automation? If so, can you share what you have so far?

Or are these manual subtasks created by the user via the UI and you only need to automate the date field?

If so, do the parent task and the sub-task share the same workflow? Or are they different workflows?

You should be able to copy the date from the parent in a postFunction on the Create transition for the sub-task workflow.

If you have a recent version of scriptrunner, you don't even need a script. You can just use the "copy field values" feature.  Never mind that ... it won't work because of your need to have 5 days before

If you really want to use a script, it would look like this

import com.atlassian.jira.component.ComponentAccessor
if(issue.parent){
def originalDueDateCf = ComponentAccessor.customFieldManager.getCustomFieldObjectsByName('Original due date')[0]
def dueDateCf = ComponentAccessor.customFieldManager.getCustomFieldObjectsByName('Need By date')[0]
def originalDueDate = issue.parent.getCustomFieldValue(originalDueDateCf )
if(originalDueDate ){
issue.setCustomFieldValue(dueDateCf, originalDueDate-5)
}
}

 

Thanq so much for the reply

Hi ,

when i was trying to test the scripting was showing error.

 

 

Thanks.

Peter-Dave Sheehan
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Nov 23, 2021

Try using "parentObject" instead of parent.

def originalDueDate = issue.parentObject.getCustomFieldValue(originalDueDateCf )
Like Ravi Kanth likes this

Hi Peter,

I Thanqu so much that the code worked.

Thanqu for ur reply.

 

N.Ravikanth

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events