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()))
What is the error?
it must be like this
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()))
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
import com.atlassian.jira.component.ComponentAccessor;
import java.sql.Timestamp
def optionsManager = ComponentAccessor.getOptionsManager();
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def parentOptionObj = optionsManager.findByOptionId(14491L);
def childOptionObj = optionsManager.findByOptionId(14494L);
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()))
If you want to use ScriptRunner you should learn Jira Java API and basic programming. Or use any other plugin like Automation for Jira or Workflow Toolbox.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The code looks good and Thank you for the help.
Yeah am bad at this java stuff, trying to get up to it.
If you still have patience..
Coming to results, I can see validator error. This is what i was hoping to clear by code.
Caused by: [InvalidInputException: [Error map: [{}]] [Error list: [[Due Date is required., PT is required.]]] at com.googlecode.jsu.util.ValidatorErrorsBuilder.process(ValidatorErrorsBuilder.java:50) at com.googlecode.jsu.workflow.validator.GenericValidator.validate(GenericValidator.java:77) at com.atlassian.jira.workflow.SkippableValidator.validate(SkippableValidator.java:45) at com.opensymphony.workflow.AbstractWorkflow.verifyInputs(AbstractWorkflow.java:1466) at com.opensymphony.workflow.AbstractWorkflow.transitionWorkflow(AbstractWorkflow.java:1167) at com.opensymphony.workflow.AbstractWorkflow.initialize(AbstractWorkflow.java:606) at com.atlassian.jira.workflow.OSWorkflowManager.createIssue(OSWorkflowManager.java:741) at com.atlassian.jira.issue.managers.DefaultIssueManager.createIssue(DefaultIssueManager.java:580)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I see, the problem is that validators work before the post function. If you set a post function, then you do not need a validator. Your post function will fill all the fields anyway.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.