Grid Row Count in Edit Mode



When loading the script in a scripted validator you will encounter static type checking errors as documented on the adaptavist script runner documentation site.
https://scriptrunner.adaptavist.com/latest/jira/#_static_type_checking .
As we are not able to import the table grid classes, we cannot fix these errors 

Note however that these check are harmless and the script should work as is.

 

When using the script runner you will probably encounter a 'Static type error'.  T

Grid Row Count in Edit Mode
/** * Since TGE 1.19 only! Can be used only as scripted validator of issue transition. * Cannot be run from the Script Console. */ import com.atlassian.crowd.embedded.api.User import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.issue.CustomFieldManager import com.atlassian.jira.issue.fields.CustomField import com.atlassian.jira.security.JiraAuthenticationContext import com.atlassian.jira.user.ApplicationUser import com.atlassian.plugin.PluginAccessor import com.opensymphony.workflow.InvalidInputException // find TGE custom field String tgeCustomFieldName = "TGE_TEST"; CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager(); CustomField tgeCustomField = customFieldManager.getCustomFieldObjectByName(tgeCustomFieldName); String tgeCustomFieldId = tgeCustomField.getId(); // get user PluginAccessor pluginAccessor = ComponentAccessor.getPluginAccessor(); JiraAuthenticationContext jiraAuthenticationContext = ComponentAccessor.getOSGiComponentInstanceOfType(JiraAuthenticationContext.class); Object userObject = jiraAuthenticationContext.getLoggedInUser(); User user = userObject instanceof ApplicationUser ? ((ApplicationUser) userObject).getDirectoryUser() : (User) userObject; // get row count Class dataManagerClass = pluginAccessor.getClassLoader().findClass("com.idalko.jira.plugins.igrid.api.data.TGEGridTableDataManager"); def tgeGridDataManager = ComponentAccessor.getOSGiComponentInstanceOfType(dataManagerClass); Integer rowCount = 0; StringBuilder result = new StringBuilder(); try { rowCount = tgeGridDataManager.getRowCountInEditMode(issue, tgeCustomField, user); result.append("TGE row count: " + rowCount); } catch (Exception e) { result.append("Grid ID=" + tgeCustomFieldId + " row count for issue ID=" + issue.getId() + " cannot be retrieved: " + e.getMessage() + "\n"); } // check if the grid is empty if (rowCount == 0) { // throw an exception with the field ID and an error message for TGE field // it will prevent transition with the noted error, user will stay on the transition screen invalidInputException = new InvalidInputException(tgeCustomFieldId, "Add at least one record to TGE grid to proceed"); throw invalidInputException; } println(result.toString()); return result.toString();