Starting from v 1.19.0 there is a more convenient way to do this task using Table Grid Editor API. Check "Validate grid data on transition" article
IntroductionAssume you track actions with a grid, and you want to validate that all rows in a grid have status 'Done'.
We use the script runner to implement a script validator which will request the content of the grid using a REST call,
traverse the rows and fail the validator when a status is found different from 'Done'
- Install the Script Runner add-on from the Atlassian marketplace
- Create a workflow with a transition 'All done'
- This transition should have a dialog box containing the grid
- Add a validator function of type 'Script Validator' and choose 'Custom Script validator'
- Point the script file parameter to the script location.
- you can use relative paths but this goes beyond the scope of this faq.
- using a script file instead of an inline script allows you to easily change the content, without editing the workflow
The complete script is avaliable as a snippet:
To retrieve the content of the grid, we use a REST call
Note about the tempId
When a table grid is being edited, all the rows relating to the issue under edit will be stored in a temporary table.
This allows the table grid to cancel an update (in case a user would hit 'cancel').
Given that the edited values are only flushed to the permanent table after the completion of the transition (as a postfunction),
we need a way to access the content of the temporary table, if we want to check if all the statusses have been set to 'Done'
The tempId will allow us to get to this content.
The addon also uses a 'command pattern' to queue all the changes that need to be done to the permanent table. This is
contained in the customFieldValue of the transition when the transition is saved
For instance, when you add a row, the customFieldValue will contain following entries
Using following code we will extract the tempId
Parameters in the script
Although this is mainly an example how to use REST to access the grid content, you can use following parameters
to configure the behaviour