I want to create a subtask on parent issue create transition using Script post function>create a subtask.
In Additional issue actions, I want to pass two fields so that subtask gets created with them
1. cascading select(parent 1, child 6)
2. Due date
I tried different ways of code by its not helping me.
Note:
If a user creates a subtask in a regular way, I have a validator to check due date and cascading select is required. just to satisfy this workflow function I need above-said fields to be prepopulated while creating a subtask automatically when a parent is created.
Sample code i tried and found some pieces of code from Atlassian community
import com.atlassian.jira.component.ComponentAccessor;
import java.sql.Timestamp
def optionsManager = ComponentAccessor.getOptionsManager();
def parentOptionObj = optionsManager.findByOptionId(14491);
def childOptionObj = optionsManager.findByOptionId(14494);
Map<String,Object> newValues = new HashMap<String, Object>();
newValues.put(null, parentOptionObj);
newValues.put("1", childOptionObj);
return newValues;
def cf = customFieldManager.getCustomFieldObjects(issue).find {it.name == 'Due'}
issue.setCustomFieldValue(cf, new Timestamp(new Date(2001,01,01).getTime()))