Postfunction velocity input template parameter retrieval problem!

Good day.

I am fairly new to jira development, I have searched for a similar topic and found nothing, so, hopefully, this will not be a double question.

I have a problem with getting a velocity input parameter in the factory class, count in this case. I can not retrieve it from the FunctionDescriptor, can anyone please tell me what I am doing wrong?

This is the code in the input/edit velocity template:

    <td class="fieldLabelArea">
        Number of subtasks:
    <td nowrap>
        <input name="count" id="count" value="$count"/>

the view template:

Creates a subtask/subtasks for a transitioning issue! Current number of subtasks for a transitioning issue is set to $count!

 And the postfunction factory class:

public class CreateSubTaskForIssuePostFunctionFactory extends AbstractWorkflowPluginFactory implements WorkflowPluginFunctionFactory{
    private static final Logger log = LoggerFactory.getLogger(CreateSubTaskForIssuePostFunctionFactory.class);
    private final static String COUNT="count";
    private final static String DEFAULT_COUNT="1";
    protected void getVelocityParamsForEdit(Map<String, Object> velocityParams, AbstractDescriptor abstractDescriptor) {

    protected void getVelocityParamsForInput(Map<String, Object> velocityParams) {
        velocityParams.put(COUNT, DEFAULT_COUNT);

    protected void getVelocityParamsForView(Map<String, Object> velocityParams, AbstractDescriptor abstractDescriptor) {
            velocityParams.put(COUNT, getCount(abstractDescriptor));        
    private String getCount(AbstractDescriptor abstractDescriptor) {
        if(!(abstractDescriptor instanceof FunctionDescriptor)) {
            throw new IllegalArgumentException("Descriotor must be a FunctionDescriptor!");
        FunctionDescriptor functionDescriptor = (FunctionDescriptor) abstractDescriptor;
        String numberOfSubtasks = (String) functionDescriptor.getArgs().get(COUNT);
        if (numberOfSubtasks == null)log.error("Something is wrong! Count is: "+numberOfSubtasks);
        return (numberOfSubtasks != null && numberOfSubtasks.trim().length()>0)?numberOfSubtasks:DEFAULT_COUNT;
    public Map<String, ?> getDescriptorParams(Map<String, Object> formParams) {
        if(formParams != null && formParams.containsKey(COUNT)) {
            return, extractSingleParam(formParams, COUNT));
        return MapBuilder.emptyMap();



1 answer

1 accepted

This widget could not be displayed.
Alexey Matveev Community Champion Jan 12, 2018


Here is my code which works. Try to compare.

My edit vm

    <td class="fieldLabelArea">
    <td nowrap>
        <textarea class="textarea" name="jsonField" id="jsonField" >$jsonField</textarea>

My view vm

$i18n.getText("cint_post.json.message") '$jsonField'

My class

import com.atlassian.jira.plugin.workflow.AbstractWorkflowPluginFactory;
import com.atlassian.jira.plugin.workflow.WorkflowPluginFunctionFactory;
import com.atlassian.jira.workflow.JiraWorkflow;
import com.atlassian.jira.workflow.WorkflowManager;
import com.atlassian.plugin.spring.scanner.annotation.imports.ComponentImport;
import com.opensymphony.workflow.loader.*;
import webwork.action.ActionContext;

import javax.inject.Inject;
import javax.inject.Named;
import java.util.HashMap;
import java.util.Map;

 * This is the factory class responsible for dealing with the UI for the post-function.
 * This is typically where you put default values into the velocity context and where you store user input.
public class CintCreateOrUpdateFactory extends AbstractWorkflowPluginFactory implements WorkflowPluginFunctionFactory
    public static final String FIELD_MESSAGE = "jsonField";

    private WorkflowManager workflowManager;

    public CintCreateOrUpdateFactory(@ComponentImport WorkflowManager workflowManager) {
        this.workflowManager = workflowManager;

    protected void getVelocityParamsForInput(Map<String, Object> velocityParams) {
        Map<String, String[]> myParams = ActionContext.getParameters();
        final JiraWorkflow jiraWorkflow = workflowManager.getWorkflow(myParams.get("workflowName")[0]);

        //the default message
        velocityParams.put(FIELD_MESSAGE, "" );


    protected void getVelocityParamsForEdit(Map<String, Object> velocityParams, AbstractDescriptor descriptor) {
        getVelocityParamsForView(velocityParams, descriptor);

    protected void getVelocityParamsForView(Map<String, Object> velocityParams, AbstractDescriptor descriptor) {
        if (!(descriptor instanceof FunctionDescriptor)) {
            throw new IllegalArgumentException("Descriptor must be a FunctionDescriptor.");

        FunctionDescriptor functionDescriptor = (FunctionDescriptor)descriptor;
        String message = (String)functionDescriptor.getArgs().get(FIELD_MESSAGE);

        if (message == null) {
            message = "No Message";


    public Map<String,?> getDescriptorParams(Map<String, Object> formParams) {
        Map params = new HashMap();

        // Process The map
        String message = extractSingleParam(formParams,FIELD_MESSAGE);

        return params;


Thank you very much for your prompt response! The problem was with using "count" in the velocity context, once I have renamed it to something else it worked! Now I  just need to validate the fact that is a numeric value and I am done

Suggest an answer

Log in or Sign up to answer
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Posted Wednesday in New to Jira

Are you planning to trial, or are currently trialling Jira Software? - We want to talk to you!

Hello! I'm Rayen, a product manager at Atlassian. My team and I are working hard to improve the trial experience for Jira Software Cloud. We are interested in   talking to 20 people planning t...

112 views 2 0
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you