Hi
The script works and was detected when i click scan. However, it does not show up in the auto complete dropdown. I thought typing "project in p" should give me "projectsSharingWorkflowScheme" in the suggestions dropdown.
I need to know the exact query name for me to use it . Am I missing some configuration?
Thanks
package com.onresolve.jira.groovy.jql import com.atlassian.jira.component.ComponentAccessor; import com.atlassian.jira.plugin.jql.function.JqlFunctionModuleDescriptor; import com.atlassian.jira.project.Project; import com.atlassian.jira.project.ProjectManager; import com.atlassian.jira.util.MessageSetImpl; import com.atlassian.jira.workflow.WorkflowScheme; import com.atlassian.jira.workflow.WorkflowSchemeManager; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.atlassian.jira.JiraDataType; import com.atlassian.jira.JiraDataTypes; import com.atlassian.jira.jql.operand.QueryLiteral; import com.atlassian.jira.jql.query.QueryCreationContext; import com.atlassian.jira.plugin.jql.function.AbstractJqlFunction; import com.atlassian.jira.util.MessageSet; import com.atlassian.jira.util.NotNull; import com.atlassian.query.clause.TerminalClause; import com.atlassian.query.operand.FunctionOperand; import com.google.common.collect.Iterables; import com.atlassian.crowd.embedded.api.User; import com.atlassian.jira.user.UserHistoryItem; import com.atlassian.jira.user.UserProjectHistoryManager; import java.util.Collections; import java.util.LinkedList; import java.util.List; public class projectsSharingWorkflowScheme extends AbstractScriptedJqlFunction implements JqlFunction { @Override String getDescription() {"returns projects sharing the same workflow scheme"} @Override List<Map> getArguments() { [ ["description": "project key", "optional": false] ] } @Override String getFunctionName() {"projectsSharingWorkflowScheme"} @Override JiraDataType getDataType(){JiraDataType.PROJECT} @Override boolean isList(){true} @Override public MessageSet validate(User searcher, FunctionOperand operand, TerminalClause terminalClause) { MessageSet messages = new MessageSetImpl(); final List<String> arguments = operand.getArgs(); if (arguments.isEmpty()) { messages.addErrorMessage("You need to specify at least one project key"); return messages; } else { for(String pKey : arguments) { if(ComponentAccessor.getProjectManager().getProjectObjByKey(pKey)==null) { messages.addErrorMessage("Project key, " + pKey + " is not valid"); } } } return messages; } public List<QueryLiteral> getValues(QueryCreationContext queryCreationContext,FunctionOperand operand, TerminalClause terminalClause) { WorkflowSchemeManager wfsm = ComponentAccessor.getWorkflowSchemeManager(); ProjectManager prjm = ComponentAccessor.getProjectManager(); final List<String> arguments = operand.getArgs(); final List <Project> projects = ComponentAccessor.getProjectManager().getProjectObjects(); final List <QueryLiteral> literals = new LinkedList<QueryLiteral>(); for(final String pKey : arguments) { final WorkflowScheme wfs = wfsm.getWorkflowSchemeObj(prjm.getProjectObjByKey(pKey)); for(final Project project : projects) { if( wfsm.getWorkflowSchemeObj(project).getId() == wfs.getId()) { literals.add(new QueryLiteral(operand,project.getId())); } } } return literals; } }
Community moderators have prevented the ability to post new answers.
It is JiraDataTypes.PROJECT, not JiraDataType.PROJECT.
You should be getting a compile error...?
Ah that was silly of me.. Didnt take a closer look at the logs and it wouldnt have happened if I used an IDE. Thanks. Works now.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I am on JIRA 6.3.15 and scriptrunner 3.1.3. Script is place in scriptroot
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.