Hi all,
I am trying to write a script via script runner plugin to insert an issue into a structure within a worklog transition. I am using the official Aptavist Script Runner Example to "Add Issue to Structure on Transition" but I always get the folowing error:
com.almworks.jira.structure.api.error.StructureException: No access to item com.almworks.jira.structure:type-issue - structure ITEM_NOT_EXISTS_OR_NOT_ACCESSIBLE
What could be the reason?
Thanks,
Richard
...
StructureComponents structureComponents
def structureManager = structureComponents.getStructureManager()
def forestService = structureComponents.getForestService()
Issue issue = issue
def structures = structureManager.getStructuresByName("XXX", PermissionLevel.ADMIN)
if (structures) {
def structureId = structures.first().id
forestService.getForestSource(ForestSpec.structure(structureId))
.apply(new ForestAction.Add(CoreIdentities.issue(issue.id), 0, 0, 0))
}
Hi Egor,
at first I thought we were getting closer to the solution. The issue is not in the index. But after indexing and searching again, it still doesn't seem to be there.
2019-02-07 17:33:43,438 DEBUG [acme.script]: issue is in the index: false 2019-02-07 17:33:43,438 DEBUG [acme.script]: reindexing issue... 2019-02-07 17:33:43,439 DEBUG [acme.script]: issue is in the index: false 2019-02-07 17:33:43,595 WARN [acme.script]: Issue Id: 219009
Regards,
Richard
Hi Richard,
This is very strange and we are out of ideas at the moment. Perhaps, this is a question to Atlassian support, but we would like to look at logs first. Can you log an issue with us (you can simply send email to support@almworks.com) and we will provide instructions on collecting the logs?
Sorry for the inconvenience.
Regards,
Egor
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Egor,
thans for your reply, but your solution does not work.
(1) The issue with the given id exist in Jira. As you can see below I have added a log output for issue.getId().
(2) The user has sufficient rights. The error even occurs for an user with administrative rights.
The script worked very well for a long time. Only with the (overdue) change to JIRA version 7.xx this error occurred. The issue is created by another script and should automatically be included in the structure within the workflow action "create" by this script.
2019-02-05 15:36:41,994 WARN 936x30268x1 18kbeqd /secure/CommentAssignIssue.jspa [c.o.s.jira.workflow.ScriptWorkflowFunction] Issue Id: 218998
2019-02-05 15:36:41,994 WARN 936x30268x1 18kbeqd /secure/CommentAssignIssue.jspa [c.o.s.jira.workflow.ScriptWorkflowFunction] Issue Key: xxxxxxxxxx
2019-02-05 15:36:41,997 ERROR 936x30268x1 18kbeqd /secure/CommentAssignIssue.jspa [c.o.s.jira.workflow.ScriptWorkflowFunction] *************************************************************************************
2019-02-05 15:36:41,997 ERROR 936x30268x1 18kbeqd /secure/CommentAssignIssue.jspa [c.o.s.jira.workflow.ScriptWorkflowFunction] Script function failed on issue: xxxxxxxx, actionId: 1, file: /xxxxxxxx.groovy
com.almworks.jira.structure.api.error.StructureException: No access to item com.almworks.jira.structure:type-issue/218998 - structure ITEM_NOT_EXISTS_OR_NOT_ACCESSIBLE (code:4700 item:com.almworks.jira.structure:type-issue/218998)
at com.almworks.jira.structure.api.error.StructureException$Builder.build(StructureException.java:505)
at com.almworks.jira.structure.api.error.StructureException$Builder.withMessage(StructureException.java:457)
Regards,
Richard
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Richard,
Here is another suggestion. This exception may also occur when Structure can't find the given issue in the index. So there is a possibility that issue was created but not reindexed at the moment of the script execution. There is a way to check it.
Please, try to find issue in the index. It can be done by adding the following code to the script:
import org.apache.log4j.Logger import org.apache.log4j.Level import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.issue.search.SearchProvider import com.atlassian.jira.jql.builder.JqlQueryBuilder import com.atlassian.query.operator.Operator ... def log = Logger.getLogger(""com.acme.script"") log.setLevel(Level.DEBUG) Issue issue = issue def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser() def searchProvider = ComponentAccessor.getComponentOfType(SearchProvider) def query = JqlQueryBuilder.newBuilder().where().addNumberCondition("id", Operator.EQUALS, issue.id).buildQuery() def count = searchProvider.searchCount(query, user) log.debug "issue is in the index: ${count == 1}" ...
You'd be able to check in the logs whether an issue is in the index or not.
If it is not, you should perform a reindex for the issue before adding it to the structure.
So this is a suggested change to the script:
import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.issue.index.IssueIndexingService import com.atlassian.jira.util.ImportUtils ... StructureComponents structureComponents def structureManager = structureComponents.getStructureManager() def forestService = structureComponents.getForestService() Issue issue = issue // reindexing issue...def issueIndexingService = ComponentAccessor.getComponent(IssueIndexingService) def isIndex = ImportUtils.isIndexIssues(); ImportUtils.setIndexIssues(true); issueIndexingService.reIndex(issue) ImportUtils.setIndexIssues(isIndex); def structures = structureManager.getStructuresByName("XXX", PermissionLevel.ADMIN) if (structures) { def structureId = structures.first().id forestService.getForestSource(ForestSpec.structure(structureId)) .apply(new ForestAction.Add(CoreIdentities.issue(issue.id), 0, 0, 0)) }
Please, let me know it works.
Regards,
Egor
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Egor,
of course.
/secure/CommentAssignIssue.jspa [c.o.s.jira.workflow.ScriptWorkflowFunction] Script function failed on issue: xxxxxxxxx, actionId: 1, file: /xxxxxx.groovy
com.almworks.jira.structure.api.error.StructureException: No access to item com.almworks.jira.structure:type-issue/218992 - structure ITEM_NOT_EXISTS_OR_NOT_ACCESSIBLE (code:4700 item:com.almworks.jira.structure:type-issue/218992)
at com.almworks.jira.structure.api.error.StructureException$Builder.build(StructureException.java:505)
at com.almworks.jira.structure.api.error.StructureException$Builder.withMessage(StructureException.java:457)
at com.almworks.jira.structure.forest.gfs.SecuredForestSource$ActionPermissionsChecker.visit(SecuredForestSource.java:668)
at com.almworks.jira.structure.api.forest.action.ForestAction$Add.accept(ForestAction.java:131)
at com.almworks.jira.structure.forest.gfs.SecuredForestSource.checkPermissions(SecuredForestSource.java:406)
at com.almworks.jira.structure.forest.gfs.SecuredForestSource.lambda$apply$2(SecuredForestSource.java:386)
at com.almworks.jira.structure.forest.gfs.AbstractTransformingForestSource.refreshed(AbstractTransformingForestSource.java:231)
at com.almworks.jira.structure.forest.gfs.AbstractTransformingForestSource.refreshed(AbstractTransformingForestSource.java:208)
at com.almworks.jira.structure.forest.gfs.SecuredForestSource.apply(SecuredForestSource.java:382)
at com.almworks.jira.structure.api.forest.ForestSource.apply(ForestSource.java:108)
at com.almworks.jira.structure.api.forest.ForestSource$apply$0.call(Unknown Source)
at addToStructure.run(addToStructure.groovy:37)
Thx
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks, Richard,
Our developers have a couple of questions/suggestions:
StructureAuth.sudo(() -> forestSource
.apply(new ForestAction.Add(CoreIdentities.issue(issue.id), 0, 0, 0))
);
Please, let me know, if it helps.Regards,
Egor
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Richard,
Would it be possible to quote the full stack trace of the error?
Regards,
Egor Tasa
ALM Works
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.