state-machine per issue type - set value to null(no value)

Hello,
I have created state-machine per issue type to manage two custom fields.

First one is called SubType, which stores the values like - EnviroLevel, EnviroAsset and so on.
Second one is called SubState, which should contain substate for selected SubType.

This means if I have chosen SubType: EnviroLevel I can choose SubState from values: Level concept, Level done ans so on
and for SubType: EnviroAsset I can choose SubState from values: Asset concept, Asset done... etc.

I hope you got the idea. I managed to do this by State machine per issue type, but I cannot force the SubType to be empty.
Lets say I want to see SubType only when I select Type:Task, but not Type:Bug.

Here is my State machine(over simplified):

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

exports.rule = entities.Issue.stateMachine({
title: 'Show only substates values that are connected to given Subtype',
stateFieldName: 'SubState',
typeFieldName: 'SubType',
defaultMachine: {
  'test initial': {
   initial: true,
   transitions: {

   }
  }
},
alternativeMachines: {
  EnviroLevel: {
   'Enviro concept': {
    initial: true,
    transitions: {
   'Enviro done': {
    targetState: 'Enviro done'
   }
   },
   'Enviro done': {
    transitions: {
   'Enviro concept': {
    targetState: 'Enviro concept'
   }
   },
 },
EnviroAsset: {
   'Asset concept': {
    initial: true,
    transitions: {
   'Asset done': {
    targetState: 'Asset done'
   }
   }
...
 },
...
}

The code is simplified and might contain error(s), the actual State machine is circa two thousand lines long so I am not going to post it here.
Anyway the state machine sort of works I just do not know how to make the machine to allow empty SubType.

3 comments
Comment actions Permalink
Official comment

Hello,

If you need to hide the SubType field completely, I suggest you use Conditional Custom Fields. This way, you can show the SubType field only when, for example, the Type field is set to Task.

Does it meet your scenario?

Comment actions Permalink

Hello,
I am sorry, I did not describe the problem correctly. What you suggest would help if you changed Type, but let us say that we already have created an issue with SubType: EnviroLevel and SubState: Level concept, now we want to change SubType to empty value. Than the state machine encounters a problem, because it is in SubState: Level concept and this SubState is not defined for empty SubType and this error occurs(see picture in attachment). On the picture the NoSubType value is EMPTY value that is named.

I managed to solve the problem by creating SubType named "No SubType", but that is not so clean solution and I think that there must be a better way.
But I guess you will eventually need to see full state machine to get the idea what am I doing.

0
Comment actions Permalink

Hello,

Thank you for the clarification. If you do not set any type's value, your state should contain the transitions specified in the defaultMachine property. So, if you specify any default transitions, they will be shown when SubType is null.

Please refer to the State-machines per Issue Type example for more information. I hope this helps. 

0

Please sign in to leave a comment.