Applying propertie '.becomesRemoved' to an issue

Hello, community!
I'm trying to figure out the "issue.becomesRemoved" - it is necessary to send a Request to a third-party API when deleting an Issue. The following code does nothing and does not return:
 

const entities = require('@jetbrains/youtrack-scripting-api/entities');
const workflow = require('@jetbrains/youtrack-scripting-api/workflow');
const conn = require('helpers/connect');
exports.rule = entities.Issue.onChange({
 title: 'Delete event from third party service',
 guard: (ctx) => {
   return ctx.issue.becomesRemoved;
 },
 action: (ctx) => {
   const issue = ctx.issue;
   let idevent = issue.fields.IDevent; // Field in the task
if (issue.becomesRemoved) {
   const connCal = conn.connCal();
   const respCal = connCal.deleteSync(/ ... uri from api ... /' + idevent, null);
 } 
},
 requirements: {
   IDevent: {
     type: entities.Field.stringType,
   }
 }
});

Is it possible to implement it in this way? And how?
Thanks!

0
3 comments

Hello,

I'm Lena from the YouTrack Team. 

To make your onChange rule triggered when an issue becomes removed, you'll need to specify the runOn attribute in the rule's declaration. For your purposes, the value should be as follows:

runOn: {
  change: false,
  removal: true
}
1

Thank you very much, Lena! It's working!

0

Please sign in to leave a comment.