Setting fields on generated Issue does not work.

I have a single-valued enum field called Issue Type that can be either Epic or Task. When I create an Epic I want to auto-generate some tasks underneath it. The issues are generated but I am unable to set the value of Issue Type to Task. What am I doing wrong?

var newIssue = function(ctx, summary){
return new entities.Issue(ctx.currentUser, ctx.issue.project, summary);
};

exports.rule = entities.Issue.onChange({
title: 'On-create',
guard: function(ctx) {
var issue = ctx.issue;
return issue.isReported && issue.becomesReported && issue.fields.IssueType.name == ctx.IssueType.Epic.name;;
},
action: function(ctx) {
var subtasks = [
newIssue(ctx, "Part A"),
newIssue(ctx, "Part B"),
newIssue(ctx, "Part C")
];

for(var i=0; i<subtasks.length; i++){
subtasks[index].fields.IssueType = ctx.IssueType.Task; // this does not work, it's generated as an Epic.

// this line claims that it is set to Task, but it is generated as Epic.
console.log("Subtask["+i+"="+subtasks[i].fields.IssueType);
}
},
requirements: {
IssueType: {
name: 'Issue Type',
type: entities.EnumField.fieldType,
Epic: {},
Task: {}
}
}
}

 

3 comments
Comment actions Permalink

Hello,

Could you please share a screenshot of Projects -> your project -> Edit project -> Fields -> IssueType page? 

Thank you. 

0
Comment actions Permalink

Could you please add two lines inside of the "for" loop and show me the output?

console.log(subtasks[index].fields.IssueType);
console.log(ctx.IssueType.Task);

 

0

Please sign in to leave a comment.