Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Using queryDslAccessor with scriptrunner?

Charlie Misonne
Community Champion
December 17, 2024

Hi!

Did someone ever manage to use QueryDslAccessor properly?

I have a custom REST endpoint with scriptrunner in Jira to import issues from another system.

A step I'm missing is to alter the updated date which can not be done with the IssueManager or any other obvious methods I'm aware of.

I read about QueryDslAccessor but it does not seem to update anything.

In this example I try to alter the summary. The real use-case is to alter the updated date. But even this is not working:

 

 

import com.atlassian.jira.database.QueryDslAccessor

import com.atlassian.jira.model.querydsl.QIssue

import com.atlassian.jira.component.ComponentAccessor

def issue = ComponentAccessor.IssueManager.getIssueObject("DET-12")

QueryDslAccessor queryDslAccessor = ComponentAccessor.getComponent(QueryDslAccessor.class);

QIssue qissue = QIssue.ISSUE

     queryDslAccessor.execute(dbConnection -> {

             dbConnection.update(QIssue.ISSUE)

                     .set(QIssue.ISSUE.summary, "Hello World")

                     .where(QIssue.ISSUE.key.eq(issue.key))

                     .execute();

     });
I'm executing this in the Script Console just to test.
There is no error but when I look at that issue in the UI or in the database directly nothing changes.

1 answer

Suggest an answer

Log in or Sign up to answer
0 votes
Ram Kumar Aravindakshan _Adaptavist_
Community Champion
December 18, 2024

Hi @Charlie Misonne,

Have you tried using ScriptRunner's HAPI feature?

With HAPI, there are simpler ways to update the issue. For example:-

def issue = Issues.getByKey('ABC-1')
            
issue.update {
   setSummary('an updated summary')
   setDescription('hello *world*')
}

For more information on updating issues with HAPI, please refer to this ScriptRunner Documentation.

I am looking forward to your feedback.

Thank you and Kind regards,
Ram

 

Charlie Misonne
Community Champion
December 19, 2024

Hi Ram,

Thanks for your answer. Yes I used HAPI in the past.

But can I updated the updated date of an issue with HAPI? I don't think so but if I'm overlooking it please let me know.

As mentioned in my question it is the updated field I need to adapt. In my example I only used summary to simplify the case to make sure I did not run into any date formatting issues.

TAGS
AUG Leaders

Atlassian Community Events