Re-set properties on a cloned ticket

How can I go about using workflows to modify a cloned ticket? I need to re-set properties to default, but retain description and title.

Inside the default clone workflow I have this code:

if(ctx.issue.fields.Type.name == ctx.Type.Test.name) // If duplicated issue was a Test
{
workflow.message(workflow.i18n('I am inside the loop'));
newIssue.fields.SuccessState.name = newIssue.fields.SuccessState.NotTested; // Reset Test State - nothing happens
}

And these requirements:

requirements: {
Type: {
type: entities.EnumField.fieldType,
Test: {}
},
SuccessState: {
type: entities.State.fieldType,
Pass: {},
NotTested: {
name: 'Not Tested'
}
}
}

 

The original is cloned, loop is entered, but the newIssue never gets its property value changed. I'm guessing it's something like "you can't modify a new ticket from a workflow that executed on the original ticket." So do I need a new workflow? I can't find any guidance on how to make changes to a ticket on creation.

 

Thanks in advance!

0
5 comments
Official comment

Hello,
Since a newly created issue is outside the context, we suggest you set the field value using square brackets:
newIssue.fields[ctx.SuccessState.name] = ctx.SuccessState.NotTested;
I hope it will be helpful. 

For urgent requests, please use this form for creating tickets: https://youtrack-support.jetbrains.com/hc/en-us/requests/new?ticket_form_id=66282.

Avatar
Permanently deleted user

Anyone around who can help me with this?

0
Avatar
Permanently deleted user

Hi Oleg, I eventually found that form and submitted the same request there yesterday, although I haven't had a response yet.

 

In the meantime while waiting i realised that I can't use the default clone workflow because there are requirements that many of my projects do not have. I only want this action to occur for one issue type, in one particular project. So I have started by creating a whole new workflow, which was one of the approaches I was considering when I created this ticket. 

I now have the code below, which is expected to act on the newly created ticket (the clone), however it is not performing the action. I can't find a useful explanation for becomesReported or isReported in the documentation, so I am growing very frustrated with what I can't imagine are exactly edge cases. Do these properties even apply to cloning? I'm doing what I consider to be basic stuff, but not finding the documentation or examples to support. Lack of debugging is a nightmare. I can't even proof of concept anything to know I have the right approach, so I must ask:

What approach should I take to reset a ticket to its default field values on clone?

 

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

exports.rule = entities.Issue.onChange({
title: 'Clone Test Ticket',
guard: function(ctx) {
var issue = ctx.issue;
return issue.becomesReported &&
issue.fields.Type.name === ctx.Type.Test.name;
},
action: function(ctx) {
var issue = ctx.issue;
workflow.message(workflow.i18n('I am executing'));
issue.fields.SuccessState = ctx.SuccessState.NotTested;

},
requirements: {
Type: {
type: entities.EnumField.fieldType,
Test: {}
},
SuccessState: {
type: entities.State.fieldType,
Pass: {},
NotTested: {
name: 'Not Tested'
}
}
}
});

0

Hello,

We responded to your ticket on the same day. Would you please check if the reply message has been marked as spam?

As for the main issue, it is not necessary to create an additional rule for changing cloned issues fields. Instead, we recommend you change the required fields in the same rule that clones the issue. For example:

var newIssue = ctx.issue.copy();
newIssue.fields[ctx.SuccessState.name] = ctx.SuccessState.NotTested;

I hope this helps.

0
Avatar
Permanently deleted user

Hi Oleg, as it is more convenient for me to operate via the ZenDesk email I have replied there and I am going to continue discussion of this issue, rather than duplicating communication.

 

(Also the link for that ticket doesn't work for me)

0

Please sign in to leave a comment.