Populate field with calculation when another field is changed

Hi, I need to multiply the estimation field by a level of difficulty when the estimation field is changed and put that value in a third field for total estimation. Does anyone have an idea on how to do this? I am a workflow noobe but an old developer, any help with be greatly appreciated. 

 

thanks in advance for any help you may give.

0
3 comments
Official comment

Hi,

I have already answered you in a support request but will duplicate the answer here just in case.

You will need an on-change workflow rule which fires when a certain condition is met. 
Here you can find several examples of workflows: https://www.jetbrains.com/help/youtrack/incloud/Default-Workflows.html.
For example, this workflow (https://www.jetbrains.com/help/youtrack/incloud/Workflow-Wont-Fix-Build.html) updates the "Fixed in Build" field when issue's state is changed to Won't Fix.

Basically, the main logic of your workflow will be very simple, a line which performs something like ctx.issue.totalEstimation = ctx.issue.Estimation * ctx.issue.levelOfDifficulty;
Besides that, you'll need to define these fields in the Requirements section (please refer to https://www.jetbrains.com/help/youtrack/incloud/requirements.html; an example can be found here: https://www.jetbrains.com/help/youtrack/incloud/Workflow-Task-Assignee.html) and compose a guard condition which defines when your workflow should trigger (please refer to https://www.jetbrains.com/help/youtrack/incloud/on-change-rules.html).
Please refer to https://www.jetbrains.com/help/youtrack/incloud/Quick-Start-Guide-Workflows-JS.html to learn workflows basics and do let me know if you face any problems.

Kindly share complete instructions (and script) on how to calculate e.g. the sum of 2+ fields!

I'll follow them and input field labels into the script.

0

Hi Julian Dumitrascu. Here is a small action rule that will use three fields: Integer Field, Integer Field 2, and Integer Fields Sum. When executed in the issue, it will sum the value of two fields and display that sum in Integer Fields Sum.

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

exports.rule = entities.Issue.action({
  title: 'Sum two integer fields',
  userInput: null,
  command: 'sum-two-integer-fields',
  guard: (ctx) => {
    return true;
  },
  action: (ctx) => { 
    const issue = ctx.issue;
    const sum = issue.fields.IntegerField + issue.fields.IntegerField2;
    issue.fields.IntegerFieldsSum = sum;
  },
   requirements: {  
    IntegerField: {    
      type: entities.Field.integerType,
          name: 'Integer Field'    
    },
     IntegerField2: {    
      type: entities.Field.integerType,
          name: 'Integer Field 2'    
    },
     IntegerFieldsSum: {    
      type: entities.Field.integerType,
          name: 'Integer Fields Sum'    
    }
  }
});

You can apply the quick fixes on the Workflows page in the project settings to add the required fields to the project. Hope this helps!

1

Please sign in to leave a comment.