Change field value depending on other field

Hi there,

i'm trying to create my first workflow which changes the value of Degree of Completion to 100 %, if the State turns to Fixed or Verified.

This is the following rule which I attached already to my project. My expectation is that when I set "Fixed" in the State field, the value in the field Degree of Completion turns to 100%. What is wrong here? Thanks a lot in advance!!!

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

exports.rule = entities.Issue.onChange({
  title: 'Set degree of completion to 100% when Fixed or Verified',
  guard: function(ctx) {
  return ctx.issue.becomesResolved;
  },
  action: function(ctx) {
  ctx.issue.fields.DegreeOfCompetion = '100%';
  },
  requirements: {
    DegreeOfCompetion: {
      name: 'Degree of completion',
      type: entities.Enum.fieldType
    }
  }
});

 

11 comments
Comment actions Permalink

Hi,

I would do this that way (It works :)):

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

exports.rule = entities.Issue.onChange({
title: 'Set degree of completion to 100% when Fixed or Verified',
guard: function(ctx) {
return ctx.issue.becomesResolved;
},
action: function(ctx) {
ctx.issue.fields.DegreeOfCompetion = ctx.DegreeOfCompetion.Completed;
},
requirements: {
DegreeOfCompetion: {
name: 'Degree of completion',
type: entities.EnumField.fieldType,
Completed: {
name:'100%'
}
}
}
});
0
Comment actions Permalink

Irina, thank you for sharing the code! 

Oksana, please let me know if you need any further assistance. 

0
Comment actions Permalink

Dear Irina and Anastasia!

Thank you very much for your assistance!!!

It seems like the problem lies elsewhere.

The thing is that i import my javascript file. Coud it be a problem?

0
Comment actions Permalink

When I export a workflow, I get a folder containing three files: .mps, .html and .js.

When I import my workflow, I zipp only my .js file for upload.

Do I need the other files?

0
Comment actions Permalink

And then again another question.

I found the code which is doing pretty much the same with other too fields. It sets the value of the field "Fixed in build" to "Never" if the status is set to "Won't fix". This code works.

But this code looks quite different to the one above. What is the difference?

 

statelessrule("Set 'Never' fixed in build for 'Won't fix' state", model.Event.BEFORE_FLUSH, function(ctx) {
  return safeCall(ctx.issue,"becomes", ["State", find("Won't fix")], false);
}, function(ctx) {
  safeCall(ctx.issue,"set", ["Fixed in build", find("Never")], null);
}).addRequirements(requirements([{name: "Issue", fields: [{name: "Fixed in build", type: {name: "Build", values: ["Never"]}}, {name: "State", type: {name: "State", values: ["Won't fix"]}}]}]));

I tried to adapt this one just by changing the names and the values, but it still doesn't work.

 

0
Comment actions Permalink

Hi Anastasia, hi Irina,

I figured out that i need an .mps file for the rule to work. Now it works. Thanks.

0
Comment actions Permalink

Oksana,

You need .mps file because you're using old workflows (MPS-based). 

Thank you for the update. 

0
Comment actions Permalink

What if I take the code of Irina and not the stateless rule I used here, how can I create an .mps? It is very likely different in that case?

0
Comment actions Permalink

You can convert .js code to .mps only manually. We'd recommend to use our JS workflow editor and create your rules using JS instead of MPS. 

0
Comment actions Permalink

You mean a web-based editor? For what I unterstand, our Youtrack version doesn't contain any web-based workflow Editor i.e. it cannot be intergrated.

Do I get you right, that in this case I have to write the code in the domain-specific language that is supported by MPS and use the external YouTrack Workflow Editor and to convert .js. into .mps for uploading them together?    

0
Comment actions Permalink

Oksana,

Sorry for the delay. Yes, if you use old external editor then you need to convert .js. into .mps to make it work there. 

0

Please sign in to leave a comment.