Returning boolean from function doesn't seem to work
I'm having trouble getting some code in my workflow to run as I would expect:
var addedComments = issue.comments.added;
var lastVisibleComment;
issue.comments.forEach(function(comment) {
if (!addedComments.has(comment) && someFunction(comment)) {
lastVisibleComment = comment;
}
});
When someFunction returns an object, it works fine:
function someFunction(comment) {
return comment.permittedGroups.find(function(g) { return g.name === 'MyGroup'; });
};
However, when someFunction returns a boolean value, the above code acts like someFunction is always returning true:
function someFunction(comment) {
if (comment.permittedGroups.find(function(g) { return g.name === 'MyGroup'; }))
return true;
return false;
};
The reason I want to use a boolean return value is that I need to add some more complicated logic in someFunction, but no matter what I do, the workflow acts like someFunction is returning true (which makes this very difficult). I have even gone so far as to make someFunction always return false to test this problem and the workflow still acts as if it is returning true.
Any ideas?
(This is in YouTrack InCloud 2017.4 Build 38361)
Please sign in to leave a comment.
Hello,
Sorry for the delay.
Could you please clarify how did you check that someFunction always returns true? I've just checked your code and everything works ok. True will be returned only if the specified group is selected in "Visible To" dropdown.
Here is the example. Let's say I've specified 'Testie Team' group instead of your 'MyGroup':
After calling someFunction(comment) I've received the following results:
Could you please attach a screenshot of issue comments with comments visibility settings and clarify which exactly group you're specifying?
Thank you!
I'll go into a little more detail:
I changed the default notify-all-unregistered-users script to change how it determines which comment should be in a reply message by changing the code in the createInReplyToMessage function to also include the results of my function:
Even when I changed someFunction to always return false, the e-mail received by my test user was still including the last comment as if someFunction was always returning true.
I'm wondering if it can take some time to propagate script changes and what I was seeing was just a result of running an older version of the scripts - since when I just now tried to reproduce this to get some screenshots, it seemed like the script was still running as previously written. A while later, I tried again and the user got the replies as I would expect. Maybe this only happens when a workflow calls functions defined in another workflow (I have a utilities workflow that just contains some helper functions that some other scripts call)?
Sorry for the false alarm.
I guess it's also possible the problem was fixed as our system is now YouTrack 2017.4 Build 38399
Hello,
Thank you for the clarification! The script changes should be propagated as soon as you save it.
Please let me know if you face the issue again.
I have now identified the problem that I was having. I also want to say that I'm probably using workflows in a way that you did not design it to be used and I do not expect it to work perfectly if that's the case. ;)
I have created a workflow called utilities that contains one custom-type module called utilities that only contains function exports like the following:
In modules of other workflows, I reference the exports in the utilities workflow module by doing the following (just an example):
So the problem comes in if I change the utilities module and do not change the modules that depend on it. The workflow code executes as if nothing has changed. This is why I thought that the function was acting as if it was always returning true (because the code that was being updated was in the utilities module).
I'm guessing this is just a limitation I'll have to live with because of the way I set things up.
EDIT: It appears this is already a known issue.
Hello,
Yes, you're right, unfortunately this is a known bug - https://youtrack.jetbrains.com/issue/JT-42120.
You can add yourself to the watchers list of the issue to receive the updates. Thank you for reaching out!