Find out what changed in an onChange event
Hi,
I've got an onChange script that gets triggered multiple times while a user is entering work item data via a timesheet. I can't work out what is changing to trigger this script. Is there some way to tell what has changed in an issue inside the onChange handler?
Thanks,
Nick
Please sign in to leave a comment.
Hi Nick,
I'm Lena from the YouTrack Team. I will do my best to help you.
There is no API which will tell you the exact change. However, you can check for particular changes and, depending on it, do this or that action. Let me explain to you with the examples:
1.You can check if a particular field value was changed
2.You can check if the issue was created:
You can also check for any other particular actions about issues, e.g. regarding the comments, fields, description, time tracking and so on. The main idea is not to understand why the workflow is triggered, but take action after the particular changes.
If you describe your final goal in greater detail, I could help you to understand which workflow you need.
Hi Elena,
Thanks for your reply. My aim is to disallow edits to all fields except for a few, such as adding work items. A simple example of what I am doing is this,
With this enabled, I get frequent popups of "This issue is read-only." while editing a work item via a timesheet. However I am still able to add the work item to an issue.
I am trying to work out what is causing the pop up to appear in this case.
As I see, you misuse the check() method. It never rolls the changes back because you hardcoded "false" as a first argument. I recommend you check for the changes there instead.
Hi,
I don't want the changes to be rolled back when I'm editing a work item, I would like work items to be the only thing that can be edited in an issue and all other fields be read only.
Rather than list every field that I want to be read only, I thought it would be easier to just check that we're not editing a work item.
The issue is this is that the check message keeps appearing when a work item is open in the timesheet view, even if I'm making no changes at the time.
Thanks,
Nick
I managed to reproduce the issue, and our developers have already fixed it: https://youtrack.jetbrains.com/issue/JT-73230/Redundant-workflow-calls-on-workItem-draft-creation. We will publish the fix in one of the upcoming releases.
Please let me know fi you have any further questions.