Set a Description Based on Value of a Custom Field (Issue Type)

Version 2018.1 

I'm trying to write a workflow to populate the description field of an issue with a template if the description field is currently empty and the custom field "Type" becomes "Incident." Type is a single-value enum custom field assigned to the same project that the workflow is assigned to. 

First question: Where does console.error() and console.log() output end up? I didn't see these messages in editor console. I'd like to inspect the values in ctx, issue, etc. 

Second question: How do I access the custom field Type from the guard function? I get the error: 

TypeError: Cannot read property "Incident" from undefined (incident_description/incident_template#17)

It doesn't like the `var becomesIncident= ` line

 

workflow code: 


var entities = require('@jetbrains/youtrack-scripting-api/entities');

exports.rule = entities.Issue.onChange({
title: 'Incident_template',
guard: function(ctx) {
var becomesIncident = ctx.issue.fields.becomes(ctx.Type, ctx.Type.Incident);
var descriptionEmpty = ctx.issue.description === null;
console.error("OHAI");
return becomesIncident && descriptionEmpty;

},
action: function(ctx) {
var issue = ctx.issue;
var description = '#Incident Report\n';
issue.description=description;

},
requirements: {
// TODO: add requirements
}
});




 

Docs I've looked at: 

https://www.jetbrains.com/help/youtrack/standalone/using-workflow-api.html

https://www.jetbrains.com/help/youtrack/standalone/Default-Custom-Fields.html 

https://www.jetbrains.com/help/youtrack/standalone/v1-Issue.html#becomes

https://www.jetbrains.com/help/youtrack/standalone/Quick-Start-Guide-Workflows-JS.html#write-first-rule-quick-start

 

 

 

 

 

1 comment
Comment actions Permalink
Official comment

Hello,

You need to define ctx.Type.Incident object. Please add the following to the Requirements section:

Type: { 
type: entities.EnumField.fieldType,
Incident: {}
}

 

Console.log() writes to the editor console - you haven't see anything because of incorrect requirements.
Please let me know if it helps. 

Please sign in to leave a comment.