Are you in the loop? Keep up with the latest by making sure you're subscribed to Community Announcements. Just click Watch and select Articles.

×
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

Display respective label if date is closer to due date in ScriptRunner

Jeremy Chee
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
Sep 21, 2023

I'm still learning how to create custom script fields on ScriptRunner (JIRA) and I'm working on this exercise where I am required to query for an issue's due date and display the respective label when it approaches the due date:
- "Green" - 10 days from the due date
- "YELLOW" - over 4 days but less than 10 days away from the due date
- "RED" - less than 4 days from the due date

1 answer

1 accepted

0 votes
Answer accepted
Jeremy Chee
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
Sep 24, 2023

Here's the solution to my question if anyone is curious 


```

import java.time.Duration;
import java.time.LocalDateTime;
import groovy.xml.MarkupBuilder

def dueDateField = issue.getDueDate();
def fieldContent = "";

if(!dueDateField) {
    log.warn("Due date doesn't exist on this item")
    fieldContent = "Due date doesn't exist on this item"
    return;
}

def currDate = LocalDateTime.now();
def daysRemaining = Duration.between(currDate, dueDateField.toLocalDateTime()).toDays();
def messageColour = "";
StringWriter writer = new StringWriter()
def builder = new MarkupBuilder(writer)

log.warn("due date field: $dueDateField, current date: $currDate");
log.warn("difference: $daysRemaining");

if(!dueDateField) {
    // log.warn("Due date doesn't exist on this item")
    fieldContent = "Due date doesn't exist on this item"
    return;
}

if(daysRemaining <= 4) {
    messageColour = "error"
    fieldContent = "You have less than 4 days left till this ticket is due!"
} else if (daysRemaining >= 10) {
    messageColour = "success"
    fieldContent = "There is still $daysRemaining days remaining until this ticket is due."
} else {
    messageColour = "warning"
    fieldContent = "There is only $daysRemaining days remaining until this ticket is due."
}

builder.div(class: "aui-message aui-message-$messageColour shadowed") {
    p(class: 'title') {
        strong("$fieldContent")
    }
}

writer.toString()

```

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
TAGS
AUG Leaders

Atlassian Community Events