How to pass multiple parameters to jira custom service?

Hi All,

I am writing an add on. I wrote a custom service which should take two parameters from the UI and print it.

But It was taking the first property and ignoring the second property.

Service.class

package com.kworks.timeinstatus.services;
import com.atlassian.configurable.ObjectConfiguration;
import com.atlassian.configurable.ObjectConfigurationException;
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.service.AbstractService;
import com.opensymphony.module.propertyset.PropertySet;

import java.io.*;
import com.atlassian.mail.Email;
import com.atlassian.mail.server.MailServerManager;
import com.atlassian.mail.server.SMTPMailServer;
import com.atlassian.jira.component.ComponentAccessor;
import javax.mail.internet.*;
import javax.mail.*;
import javax.activation.*;
import javax.mail.Multipart;
import javax.mail.internet.MimeMultipart;
import java.nio.file.Files;
import java.nio.file.Paths;


public class TimeInStatusService extends AbstractService {
    public static final String TUTORIAL = "Tutorial";
    public static final String TUTORIAL1 = "Tutorial";
    private String jql;
    private String subscriber;
    @Override
    public void init(PropertySet props) throws ObjectConfigurationException {
        super.init(props);

        if (hasProperty(TUTORIAL)) {
            jql = getProperty(TUTORIAL);
        } else {
            jql = null;
        }
        if (hasProperty(TUTORIAL1)) {
            subscriber = getProperty(TUTORIAL1);
        } else {
            subscriber = null;
        }
    }

    @Override
    public ObjectConfiguration getObjectConfiguration() throws ObjectConfigurationException {
        return getObjectConfiguration("MYNEWSERVICE", "com/kworks/services/mytimeinstatusservice.xml", null);
    }

    @Override
    public void run(){
        String result = sendmail();

        System.out.println("JQL is: "+jql+" Application User is: "+subscriber);
    }

    @Override
    public void destroy() {
        System.out.println("Let me do this before destory!");
        super.destroy();
    }

}

Service.xml

<someservice id="jtricksserviceid">
    <description>My New Service</description>
    <properties>
        <property>
            <key>Tutorial</key>
            <name>JQL</name>
            <type>string</type>
        </property>
        <property>
            <key>Tutorial1</key>
            <name>Subscriber</name>
            <type>string</type>
        </property>
    </properties>
</someservice>

Input:

Expected Result:
JQL is: Test Application User is: Kiran

Actual Result:
JQL is: Test Application User is: Test

Please Help me.

Thanks,
Kiran.

Hello @jkirankumar1993,

Your TUTORIAL1 value is still “Tutorial” in which I think you wanted it to be “Tutorial1” instead (forgot to edit after copy-paste maybe?). That’s the reason why getProperty(TUTORIAL1) is the same as getProperty(TUTORIAL).

Cheers,
Ian

2 Likes

Thanks iragudo. I forgot to edit the field name in the JAVA class :sweat_smile: Sorry for the late response.

You’re welcome, @jkirankumar1993. I guess it is fixed now?

Its fixed. I have posted another question. Can you please help me in solving that issue ?