Move the issue from current project to another.

Hi all.

I am trying to move issue from one project to another from workflow.

I've tried in two ways:

ctx.issue.applyCommand('project PROJ2');

and

var newProject = entities.Project.findByKey('PROJ2');
ctx.issue.project = newProject;

but in both cases I got errors:

Workflow developer reports error: Invalid argument: null (@jetbrains/youtrack-scripting-api/entities#308)

Is this the correct way to move issue from one project to another?

PS: from the web-interface via Command Dialog the command: 

'project PROJ2'

running successfully.

Thanks.

12 comments
Comment actions Permalink
Official comment

Hi Dmitry,

I've just tried the same rule on YT 2018.1, and it works for me.

This exception message doesn't tell much, unfortunately. Most probably, it is another rule failing, which belongs either to 'KD' or to 'KEP' project. I would suggest you to contact the support team and provide the logs of your YouTrack server.

Comment actions Permalink

Could you please show the complete code of the script that you have and tell the number of the build of your YouTrack instance?

0
Comment actions Permalink

Were you able to sort this out?

0
Comment actions Permalink

@Lo Chupa No, unfortunately, the full code was not shared.

0
Comment actions Permalink

Hi,

Sorry, I lost the previous message..

There is a full code of rule for testing:

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

exports.rule = entities.Issue.onChange({
title: 'Test_rule',
guard: function (ctx) {
return (ctx.issue.id == 'KD-10253');
},
action: function (ctx) {
try{
console.log('Try to change...');
var newProject = entities.Project.findByKey('KEP');
ctx.issue.project = newProject;
}
catch(e){
console.log(e);
}
},
requirements: {

}
});

 

Here, for testing, I trying to switch the project in issue from one to another. And got error:

Workflow ke-devops-workflows reports error: Invalid argument: null (@jetbrains/youtrack-scripting-api/entities#313)

 

maybe I'm doing it wrong?

0
Comment actions Permalink

This code doesn't work too:

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

exports.rule = entities.Issue.onChange({
title: 'Test_rule',
guard: function (ctx) {
return (ctx.issue.id == 'KD-10253');
},
action: function (ctx) {
try{
ctx.issue.applyCommand('project ke-partners');
}
catch(e){
console.log(e);
}
},
requirements: {

}
});

 

0
Comment actions Permalink

I forgot about number of build, it is:

 

 

0
Comment actions Permalink

OK, thanks. I will continue to understand myself.

0
Comment actions Permalink

Hi Dmitry,

Please try to add 2 debug lines before 

return (ctx.issue.id == 'KD-10253');

So the guard will look like this:

guard: function (ctx) {
console.log("guard section message");
console.log(ctx.issue.id);
return (ctx.issue.id == 'KD-10253');
},

And let me know the result you see in the console. 

 

0
Comment actions Permalink

Hi, 

There is output (I created the new issue KD-10283 for testing but anyway):

The code:

 guard: function (ctx) {
console.log("guard section message");
console.log(ctx.issue.id);
return (ctx.issue.id == 'KD-10283');
},

 

The output

drubtsov@46.17.202.14 05/06/18 10:23
guard section message
drubtsov@46.17.202.14 05/06/18 10:23
KD-10283
0
Comment actions Permalink

Could you please elaborate why do you use such guard condition? Do you want the rule to trigger only for one specific issue or this is just for test purposes? 

Please try the following:

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

exports.rule = entities.Issue.onChange({
title: 'Test_rule',
guard: function (ctx) {
return true;
},
action: function (ctx) {
console.log("before the command");
ctx.issue.applyCommand('project KP');
console.log("after the command);
},
requirements: {

}
});

, where KP is a short name of target project. 

Change anything in KD-10283 and let me know the error message you see on issue page and the console output.

 

Btw, I'd recommend creating a support request so we could investigate this case properly (https://youtrack-support.jetbrains.com/hc/en-us/requests/new?ticket_form_id=66282). 

0
Comment actions Permalink

Yes, I want to test this rule only for one specific issue.

There is the output:

drubtsov@46.17.202.14 05/06/18 16:10

before the command
drubtsov@46.17.202.14 05/06/18 16:10

after the command

 

And error message in web-interface:

 

Workflow ke-devops-workflows reports error: Invalid argument: null (@jetbrains/youtrack-scripting-api/entities#313)


I cant understand why 'null' ... I tried to disable any workflow in target project and had the same error.
0

Please sign in to leave a comment.