ScriptRunner validator for workflow transition not working - jira datacenter

Aira Veronica Dizon January 27, 2020

I have a table grid with two columns (column A and column B) and it's initialized with static values (no datasource). The values in column B are set to "Not Validated", but it has a checkbox to enable editing it to "Validated". And my script validator is in the "Validate" transition in the workflow.

So the scenario must be like this: when all values in column B are ticked to "Validated", and when the workflow's transition "Validate" is clicked, it must check whether all values in column B are all "Validated" before the workflow can transition to "Validated" status.

However, I'm encountering a problem with reading the table grid. I'm getting the correct issue and custom field id but it's returning an empty data. So since my validator can't read the grid data, it's not checking anything.

 

error.PNG

 

Do you know what might be the issue? 

--------------------------------------------------------------------------------------------------

Here is snippet of my code:

@WithPlugin("com.idalko.jira.plugins.igrid.api.data.TGEGridTableDataManager")
@PluginModule
TGEGridTableDataManager tgeGridDataManager

@WithPlugin("com.idalko.jira.plugins.igrid.api.config.grid.TGEGridConfigManager")
@PluginModule
TGEGridConfigManager tgeConfigManager

// get an issue
IssueManager issueManager = ComponentAccessor.getOSGiComponentInstanceOfType(IssueManager.class);
Issue issue = issueManager.getIssueObject("TEST-1");
log.info("issue: " + issue);

// find the TGE custom field
CustomFieldManager customFieldManager = ComponentAccessor.getOSGiComponentInstanceOfType(CustomFieldManager.class);
CustomField tgeCustomField = customFieldManager.getCustomFieldObject(10710);
log.info("custom field: " + tgeCustomField);

// get current user
JiraAuthenticationContext jiraAuthenticationContext = ComponentAccessor.getOSGiComponentInstanceOfType(JiraAuthenticationContext.class);
Object userObject = jiraAuthenticationContext.getLoggedInUser();
User user = userObject instanceof ApplicationUser ? ((ApplicationUser) userObject).getDirectoryUser() : (User) userObject;

// get TGE custom field
Long tgeCustomFieldId = tgeCustomField.getIdAsLong();

// read the data from the first grid
tgeGridDataManager = ComponentAccessor.getOSGiComponentInstanceOfType(TGEGridTableDataManager.class);
def rows = tgeGridDataManager.readGridData(issue.getId(), tgeCustomFieldId, null, null, 0, 10, user);
def values = rows.getValues()

StringBuilder returnResult = new StringBuilder();
returnResult.append("Grid rows: " + values + "\n");

if (!values.isEmpty()) {

rows = tgeGridDataManager.readGridData(issue.getId(), tgeCustomFieldId, null, null, 0, 10, user);
values = rows.getValues()
returnResult.append("Grid content: " + values + "\n");

} else {

rows = tgeGridDataManager.readGridData(issue.getId(), tgeCustomFieldId, null, null, 0, 10, user);
values = rows.getValues()
String msg = returnResult.append("Grid ID: " + tgeCustomFieldId + " content: " + values + "\n");
invalidInputException = new InvalidInputException(msg)
throw invalidInputException;

// check if any row has an 'Not Validated' status selected
for (int rowNumber = 0; rowNumber < values.get(values.size()); rowNumber++) {
Map<String, Object> rowData = values.get(values.size()).get(rowNumber);
Map<String, Object> status = rowData.get(
"validate" // name of the column from TGE configuration
);
String statusName = status.get(
"Not Validated" // pre-defined property for 'list', 'userlist', 'radio' column types
);
if ("Not Validated" // name of the status I want to forbid
.equals(statusName)) {
// 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, "Row #" + (rowNumber + 1) + " of TGE grid has an 'Open' status selected");
throw invalidInputException;
}
}

}



println(returnResult.toString());
return returnResult.toString();

 

 

1 answer

0 votes
Kristian Walker _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 28, 2020

Hi Aira,

Thank you for your question.

I can confirm that the reason that your code above will not work inside of ScriptRunner for Jira Cloud is due to the fact the code you have provided is for ScriptRunner for Jira Server and this will not work as Atlassian only provide a rest API in Jira Cloud and do not provide a Java API in the cloud-like they do in Jira Server.

You can see more detailed information on the differences between the cloud and server versions inside of our documentation page located here.

We would recommend reviewing the documentation for ScriptRunner for Jira Cloud which is located here along with the Jira Cloud Rest API Documentation in order to see how the REST API's work in Jira cloud.

Also, I can confirm that Validators in Jira Cloud are limited to only being able to use the Jira Expression Framework documented by Atlassian here, which means you will need to check if you can validate what you require using this in order to see if your requirement can be achieved using ScriptRunner for Jira Cloud.

Finally, I can confirm that the ScriptRunner for Jira Cloud documentation page located here explains in further details on how to add validators with the plugin.

If you are not using Jira Cloud as you have indicated above then you can ignore this message and I would advise re-tagging this post to show that you are using Jira Server or Jira Data Center so that someone with experience on this can assist yourself.

I hope this information helps.

Thanks,

Kristian

Aira Veronica Dizon February 5, 2020

Hello Kristian,

 

Sorry for the late response as I got busy with my other tasks and haven't been able to continue working on this one. 

Anyway, I'm using Jira Data Center. Do you know what code I should be using for the script validator for jira datacenter?

Kristian Walker _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 5, 2020

Hi Aira,

I am unable to advise on Jira Data Center and I would advise re-tagging your question to remove the cloud tags so that other members more experienced with how Jira Data centre works can assist yourself.

Regards,

Kristian

Suggest an answer

Log in or Sign up to answer