Conditional field visibility - accessing value before field becomes invisible

Hello,

 

in my case im using some fields as "cache" to store previous values of other fields. This fields which are used as cache has set Conditional field visibilty according to issue state. 

 

E.g i have field Assigned and ResolvedBy (both user type) and field resolved by is displayed only when issue is in resolved state. When issue enters resolved state i save ctx.currentUser into field ResolvedBy (and field is visible) but when im switching issue back from resolved state (to unresolved state) i wana to store value from ResolvedBy field into Assigned field, but it can be done because in onChange event field ResolvedBy is already hidden (and its null value).

Is there some way how i can catch some event when field is becoming invisible? Or something like that?

 

I tried onEnter and onExit in state machine (without success)

 

Then i tried onChange workflow binded on becomesInvisibleInIssue (guard condition) but without sucess too

 

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

exports.rule = entities.Issue.onChange({
// TODO: give the rule a human-readable title
title: 'When issue becomes unresolved, restore Assignee fields from ResolvedBy field.',
guard: function(ctx) {
// TODO specify the conditions for executing the rule
var issue = ctx.issue;
var project = entities.Project.findByKey(issue.project.key);
var cField = project.findFieldByName('ResolvedBy');

return cField.becomesInvisibleInIssue(ctx.issue);
},
action: function(ctx) {
var issue = ctx.issue;

console.log('ResolvedBy field: ' + issue.fields.ResolvedBy);

var project = entities.Project.findByKey(issue.project.key);
var cField = project.findFieldByName('ResolvedBy');

 

 

//issue.fields.Assignee = issue.fields.ResolvedBy;
},
requirements: {
// TODO: add requirements
}
});

1 comment
Comment actions Permalink
Official comment

Hello,

Please try using `return ctx.issue.becomesUnresolved;` to catch the event of reopening the issue. I suppose at that moment the conditional field is not invisible yet.  

However, it is not possible to access invisible fields via workflow. 

Please sign in to leave a comment.