Forums

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

Custom Fields- is there a way to build a field that changes the due date..

Jerrod Van January 31, 2024

Custom Fields- is there a way to build a field that changes the due date..

 

For example. 

we have a invoice date field

we have a invoice due date field

- want to put invoice date and then a possible drop down that you can select, 15, 30 ,60 and it auto populates the due date field. 

 

2 answers

0 votes
Jerrod Van February 1, 2024

Is this under Project settings automation?

Nic Brough -Adaptavist-
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.
February 1, 2024

Only if you want to do it with Automation.

Jerrod Van February 1, 2024

do you have an example of the automation i would choose?

 

I looked within Script Runner but i could figure out where i would add your script 

Nic Brough -Adaptavist-
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.
February 1, 2024

The script I gave was intended for the script console, but it would be easy to adapt it to run in other places.

The question is where and when do you want the calculation to happen?

Automation will need to ask you the same question - what's the trigger to do it?  I have not tried to write an Automation to do it, so I'm not sure how to approach it.

0 votes
Nic Brough -Adaptavist-
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.
January 31, 2024

Hi Jerrod,

If you have one of the scripting or automation apps, then yes.  There are different ways to do it, depending on when you want to trigger the change, and which app you're using, but if you have a recent version of Scriptrunner with HAPI, then the below will do it

Note that:

  • This script is written for the SR console.  You won't need the issuekey or issue= lines in post functions, and if it's a listener, you can use "def issue = event.issue"
  • It assumes the options in the payment terms list really are named as numbers that toInteger can translate from text into a number.
  • I did this with SR and HAPI partly because I'm an Adaptavist and it's my job to encourage people to use SR, but mostly because HAPI is easier to read as pseudocode if you wanted to use something else.
import java.time.LocalDate
import java.time.format.DateTimeFormatter

def issueKey = "ISSUE-KEY" // Replace with the actual issue key
def invoiceDateField = "Invoice Date"
def paymentTermsField = "Payment Terms"
def invoiceDueDateField = "Invoice Due Date"

def issue = Issues.getByKey(issueKey)
def invoiceDateValue = issue.getCustomFieldValue(invoiceDateField)
def paymentTermsValue = issue.getCustomFieldValue(paymentTermsField)?.value

def invoiceDate = LocalDate.parse(invoiceDateValue, DateTimeFormatter.ofPattern("yyyy-MM-dd"))

def daysToAdd = paymentTermsValue.toInteger()

def invoiceDueDate = invoiceDate.plusDays(daysToAdd)

issue.update {
setCustomFieldValue(invoiceDueDateField, invoiceDueDate.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")))
}

 

Suggest an answer

Log in or Sign up to answer