Correct format for message in javascript workflow editor
Answered
I'm trying to create a message (blue box pop-up) when an issue is submitted. I suspect my syntax is wrong, but not sure where. My script looks like:
action: function(ctx) {
var issue = ctx.issue;
if(issue.becomesReported){
message('Here I am');
}
}
The error message says:
Workflow bug-submission-workflow reports error: Can't find method jetbrains.charisma.misc.Message.show(org.mozilla.javascript.Undefined,org.mozilla.javascript.Undefined). (initialscript.js#24)
We are using youtrack 2017.2. Any suggestions on how to make this work properly?
Thanks!
Please sign in to leave a comment.
Hello Daniel! You need to use the workflow.message() method and also require the v1/workflow module where this method belongs to.
https://www.jetbrains.com/help/youtrack/incloud/2017.2/v1-Workflow.html#d199298e162
Thank you for your reply. I think I figure out what you mean, thought your documentation doesn't seem to mention it.
When you say 'require the v1/workflow' module, do you mean add the line
var workflow = require('v1/workflow');
or something like it to the top of the rule? I don't see a mention of this in the documentation, but it seemed to work. Now when I call
workflow.message('Text')
I no longer receive an error, however the message does not appear in the blue box. Am I still doing something wrong?
You need to write the following on the top of your code:
var entities = require('v1/entities');
var workflow = require('v1/workflow);
We're sorry that this is not mentioned in the documentation yet, but please note that JS workflows are an experimental feature at the moment, so the documentation is not completely ready yet.
If your message is not displayed, please check the logic of your workflow. Is it triggered at the right moment? Feel free to share your code here and describe your use case.
Totally understood. My code looks like this.
var entities = require('v1/entities');
var workflow = require('v1/workflow');
exports.rule = entities.Issue.onChange({
title: 'Bug-submission-rule',
action: function(ctx) {
var issue = ctx.issue;
if(issue.becomesReported){
if ( issue.fields.IssueType.name === 'Bug' ){
workflow.message('Here I am');
}
else{
workflow.message('Why am I here');
}
}
},
requirements: {
IssueType:{
type: entities.State.fieldType
},
BugState:{
type: entities.State.fieldType
}
// TODO: add requirements
}
});
I believe I should be falling into either the if() or the else() statement above when I press the submit button for my issue. I'm seeing a message that says the issue was submitted, but I don't see either of the other messages.
I have a custom field called 'IssueType' which has a value 'Bug'.
There is an issue with this particular case when you're trying to display a message on the becomesReported() event. In this case there is a predefined message saying that an issue was reported, and it's overlapping with all other messages, including those sent from workflows.
If you test this workflow on an Agile Board, you'll see that the workflow works as expected.
We're sorry for the inconvenience, this issue will be addressed in the nearest future.
Not a problem! Thank you for the assistance