It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

script for creating issue in Jira service desk, cause block in database

j Dec 14, 2016

the query that cause de block in db

(@P0 nvarchar(4000),@P1 nvarchar(4000),@P2 nvarchar(4000))
insert into "dbo"."AO_F1B27B_PROMISE_HISTORY" ("KEY_HASH", "TASK_KEY", "CLASSIFICATION") values ( @P0 , @P1 , @P2 )

 

 

here my script, what im doing wrong?

import com.atlassian.jira.ManagerFactory
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.project.Project
import com.atlassian.jira.issue.link.IssueLinkTypeManager
import com.atlassian.jira.issue.index.IssueIndexingService
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.IssueInputParameters
import com.atlassian.jira.bc.issue.IssueService
import com.atlassian.jira.util.ImportUtils
import org.apache.log4j.Category


def Category log = Category.getInstance("com.onresolve.jira.groovy.PostFunction")
log.setLevel(org.apache.log4j.Level.DEBUG)

log.debug ("iniciando clone ")
log.debug ("declarando variables")
def issueManager = ComponentAccessor.issueManager
def issueFactory = ComponentAccessor.getIssueFactory()
def authenticationContext = ComponentAccessor.getJiraAuthenticationContext()
def issueLinkManager = ComponentAccessor.getIssueLinkManager()
def customFieldManager =ComponentAccessor.getCustomFieldManager()
def userUtil = ComponentAccessor.getUserUtil()
def projectMgr = ComponentAccessor.getProjectManager()
def issueLinkTypeManager = ComponentAccessor.getComponentOfType(IssueLinkTypeManager.class)
def issueLinkType = issueLinkTypeManager.getIssueLinkTypesByName('Problem/Incident')[0];
def issueIndexingService = ComponentAccessor.getComponent(IssueIndexingService)
def issueService = ComponentAccessor.getIssueService();

def IssueInputParameters issueInputParameters = issueService.newIssueInputParameters();

log.debug ("Inicializando inputparameters")
issueInputParameters.setProjectId(projectMgr.getProjectObjByKey("CREOSD2").Id); //JSD project
issueInputParameters.setIssueTypeId(issue.issueType.id);
issueInputParameters.setSummary(issue.summary);
issueInputParameters.setReporterId(issue.getReporterId());
issueInputParameters.setDescription(issue.description);

log.debug ("IssueService.ValidateCreate")
IssueService.CreateValidationResult validationResult = issueService.validateCreate(authenticationContext.getLoggedInUser(), issueInputParameters); //issueObject.getReporter()
if(!validationResult.isValid())
{
log.debug("Could not create issue: " + validationResult.getErrorCollection());
}
else
{
// Create new issue
log.debug ("Trying crear issue")
IssueService.IssueResult createResult = issueService.create(authenticationContext.getLoggedInUser(), validationResult);
log.error("Issue Created")
if (!createResult.isValid())
{
log.error("Issue was not created!")
} else {
log.error("Issue was created. Issue Id: " + createResult.getIssue().getKey())
}
}

7 answers

0 votes
JamieA Dec 14, 2016

projectMgr.getProjectObjByKey("CREOSD2").Id

is wrong, should be

projectMgr.getProjectObjByKey("CREOSD2").id

You may have other problems but you should at least start with something that will compile.

 

0 votes
j Dec 14, 2016

thanks,

i used: projectMgr.getProjectObjByKey("CREOSD2").getId()

the error persists

the query that cause de block in db

(@P0 nvarchar(4000),@P1 nvarchar(4000),@P2 nvarchar(4000))
insert into "dbo"."AO_F1B27B_PROMISE_HISTORY" ("KEY_HASH", "TASK_KEY", "CLASSIFICATION") values ( @P0 , @P1 , @P2 )

0 votes
j Dec 14, 2016

if i copy/paste the script in Add-ons->SCript Ruhnner->Script Console and change the values of issueInpurtParameteres (hardcode) it works!

i dont understand why in a postfunction inside a workflow it doesnt work

0 votes
j Dec 15, 2016

Hi Jamie,

I detected this issue happens only if the target is a JIRA Service Desk Project with SLA configured.

if i delete all SLA definition, all works!

0 votes
JamieA Dec 18, 2016

What exactly do you mean by "block in db"? 

What is different when you run it in Script Console, is it the issue that you are copying?

What DMBS are you using?

0 votes
j Dec 19, 2016

Hi Jamie,

here the screen of block in database

Sin títulodb1.png

here the detail of SPID 62, the query that causes the "block"

Sin títulodb2.png

Also JIRA screen stucks, and the only way to resolve the problem, is restarting JIRA Service or kill the process (in database)

im using sql server 2008

NOTE: This problem is only with JIRA Service Desk Project with SLA configured

if i delete all SLA definition, all works!

0 votes
j Dec 19, 2016
About what is different,
i thing the example of script console is external is separate of any process, while the script in a workflow post function is inside a process of a project maybe a process of an issue, im not sure.
i tried also with Script listeners (trigerred on genericevent) but the same problem =(

 

Suggest an answer

Log in or Sign up to answer
This widget could not be displayed.
This widget could not be displayed.
Community showcase
Posted in Jira Core

How to manage many similar workflows?

I have multiple projects that use variations of the same base workflow. The variations depend on the requirements of the project or issue type. The variations mostly come in the form of new statuses ...

736 views 7 0
Join discussion

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you