Unable to create issue from my java code

Alok Singh August 4, 2015

I have written this api to create issues in JIRA 

public boolean creteIssue(String deliverable, String productName){


    ApplicationUser applicationUser = authenticationContext.getUser();
    IssueInputParameters issueInputParameters = issueService.newIssueInputParameters();

    // issueInputParameters.setSummary(req.getParameter("deliverable"));
    //issueInputParameters.setDescription(req.getParameter("deliverable"));


    issueInputParameters.setSummary(deliverable);
    issueInputParameters.setDescription(deliverable);
    issueInputParameters.setAssigneeId(applicationUser.getName());
    issueInputParameters.setReporterId(applicationUser.getName());

    String projectKey =  leangearsDiscoveryAction.getProjectKey(productName);
    Project project = projectService.getProjectByKey(applicationUser, projectKey).getProject();
    issueInputParameters.setProjectId(project.getId());

    issueInputParameters.setIssueTypeId("2");

    currentUser = authenticationContext.getLoggedInUser();
    IssueService.CreateValidationResult result = issueService.validateCreate(currentUser, issueInputParameters);
    issueService.create(currentUser, result);

    return true;

}

Now I  am trying to call this function from my velocity template. 

$action.creteIssue($discoverDeliverablesConfs.get($k).deliverable,$prod)

But it is not working. What should be the correct approach?

3 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

2 votes
Answer accepted
Volodymyr Krupach
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 5, 2015

Try $action.creteIssue("$discoverDeliverablesConfs.get($k).deliverable" , "$prod")

If it does not help try to hard code string params for creteIssue method. I guess that the problem is with resolving the strings. Also check that the plugin reloaded and your newly created "creteIssue" method was compiled. You can run atlas-clean to be sure.

Alok Singh August 5, 2015

Your suggestion of debugging this helped a lot as there was problem with the method invocation. It is working fine now but it creates the issue every time I reload the page.

Volodymyr Krupach
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 5, 2015

> but it creates the issue every time I reload the page Because this is what you coded: the method is called every time the page is loaded. You either need to persist somewhere that the issue for passed deliverable and productName is already created or in your method do a search for the issue created based on passed deliverable and productName and create it only if does not exist.

Alok Singh August 5, 2015

I was trying with this as well but then the whole layout goes for a toss <button class="aui-button aui-button-link" id="delv" onclick=$action.createIssue("$dev_feature" , "$prod")>Create Issue</button>

Volodymyr Krupach
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 5, 2015

No, you are mixing JavaScript and Java code :-). createIssue method will be called anyway when the page is rendered. You need some persisted flag to indicate that issue is already created and do not the createIssue when the flag is set.

Alok Singh August 20, 2015

Hi Volodymyr, is it possible to save the Issue Id once the issue is created ?

Volodymyr Krupach
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 20, 2015
Alok Singh August 20, 2015

Thanks Volodymyr!

0 votes
Alok Singh August 4, 2015

Method itself is not getting called. $action.creteIssue($discoverDeliverablesConfs.get($k).deliverable,$prod) itself is getting printed on the screen.

0 votes
Volodymyr Krupach
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 4, 2015

Did you debug the method? Is it invoked? If it's invoked: do you get any exception.

TAGS
AUG Leaders

Atlassian Community Events