We have a project, which tracks how many hours have been spent the ticket on a day. Because of reasons the main workhours is 8 hour which is between 8:00-16:00. But also someone might stay in the office until 20:00. There is lot of coding behind it, it is a little bit complex too.
In YouTrack 2018.2 Build 42223 I have used autoforward from Submitted to an Open Forwarder which onEnter function if the time is before 16:00 then its going to forward it to Open, and after to Open Night State. It would work out fine.
But in the YouTrack 2018.3 Build 46358 it remains in the Open Forwarder, and does not going to Open / Open night State as it should be.
I tried to look for autoforward in the YouTrack 2018.3 Help documents but i can not find anything about it.
Before 16:00
Submitted -> Open Forwarder -> Open
After 16:00
Submitted -> Open Forwarder -> Open Night
But my questions would be:
- Is it possible in Statemachine to forward it to the corresponding state depending on what time is it?
- Also can i autoforward to a targetState which is stored in a variable that can be modified between the trainsition eg: onEnter(),onExit()
- Is there anything from autoforward in the documents.
There would be my idea which worked at some point in the older build
but in the new one remains in the OpenForwarder
var entities = require('@jetbrains/youtrack-scripting-api/entities');
var forwardTo="Open";
exports.rule = entities.Issue.stateMachine({
title: workflow.i18n('Define transitions for "State" field with predefined time constraints'),
fieldName: 'State',
states: {
Submitted: {
initial: true,
onExit: function(ctx){
var date = new Date(Date.now());
if (date.getHours() < 16) {
ctx.issue.fields.OpenTime = Date.now();
forwardTo = "Open";
} else {
ctx.issue.fields.NTS = Date.now();
forwardTo = "Open Night";
}
},
transitions: {
autoforward: {
targetState: "Open Forwarder",
after: ONE_SECOND
}
}
'Open Forwarder': {
transitions: {
autoforward:{
targetState: forwardTo,
after: ONE_SECOND
}
}
},
}
...
...
...
Could you lend me a helping hand?
Also tried this below
var entities = require('@jetbrains/youtrack-scripting-api/entities');
exports.rule = entities.Issue.onChange({
title: 'Open_forwarder',
guard: function(ctx) {
return ctx.issue.fields.becomes(ctx.State.name,ctx.State.OF.name);
},
action: function(ctx) {
var date = new Date(Date.now());
var forwardTo;
if (date.getHours() < 16) {
ctx.issue.fields.OpenTime = Date.now();
forwardTo = "Open";
} else {
ctx.issue.fields.NTS = Date.now();
forwardTo = "Open Night";
}
ctx.issue.fields.State = ctx.issue.project.findFieldByName(ctx.State.name).findValueByName(forwardTo);
},
requirements: {
State:{
type: entities.State.fieldType,
name: "State",
OF:{
name: "Open Forwarder"
}
}
}
});
But because of the autoforward, which does not triggers a change in the transaction, so this module would not get triggered.
So once again, do you have any advice about this code, and also a solution to my problem? That would redirect to the corresponding state depending on the time.
Thanks in advance!