Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,558,145
Community Members
 
Community Events
184
Community Groups

How to use variables in jql query while calling an api in java?

I am trying to use a jql query in my java code.

 

HttpResponse<String> response = Unirest.get("https://sweetypareek155.atlassian.net/rest/agile/1.0/epic/none/issue").basicAuth(e,p).header("Accept", "application/json").queryString("jql", "project = 'project1' and created > '2023-03-22'").asString();

 

Here i want to replace 

2023-03-22 with a string variable storing the current date of today.

How to use a variable here in jql? 

1 answer

1 accepted

1 vote
Answer accepted
habib rahman
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.
Mar 23, 2023

Hi @sweety pareek My name is Habib. I will do my best to assist:


Also, take a look at Adaptavist Library: https://library.adaptavist.com/


To use a variable in the JQL query in your code, you can use string concatenation to combine the JQL syntax and your variable:
You can create a variable `String currentDate` and assign the current date to it using the following code:
```
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
String currentDate = dateFormat.format(new Date());
```
And then replace the hard-coded date value in your JQL query with the variable.
```
String jqlQuery = "project = 'project1' and created > " + currentDate;

HttpResponse<String> response = Unirest.get("https://sweetypareek155.atlassian.net/rest/agile/1.0/epic/none/issue")

    .basicAuth(e,p)

    .header("Accept", "application/json")

    .queryString("jql", jqlQuery)

    .asString();
```
This will dynamically insert the current date value into your JQL query based on the value stored in the `currentDate` variable.

If this helped, please accept the answer so others might also benefit from this issue.Thank you 
Habib 

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
FREE
PERMISSIONS LEVEL
Site Admin
TAGS
AUG Leaders

Atlassian Community Events