Add a dynamic number value to a date-field with JMWE

Martin Heini
Contributor
April 11, 2024

Hi, 

To add the value of a number customfield to a date field in a Set Issue Fileds Post Function  I'm trying on this way as Groovy script: 

new Date() + issue.get("customfield_21011") + 7

It didn't works. Any ideas?
Thanks, 
Martin

2 answers

1 accepted

1 vote
Answer accepted
David Fischer
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 11, 2024

Hi @Martin Heini 

I'm not sure I understand what you're trying to achieve. Is customfield_21011 your number field? And are you trying to set a Date field to "now" + a number of days equal to the value of customfield_21011 + 7 days?

When you say it doesn't work, what does it do exactly? Are you getting any errors? Are you getting a wrong date?

Martin Heini
Contributor
April 12, 2024

Hi David
Yes, this is exactely what I want to do.

Target is a customfield of type date,
customfield_21011 is of type number,
7 is a constant

David Fischer
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 12, 2024

Then the problem is that the value of your Number field is a Double (floating point), not an Integer, and Groovy doesn't know how to add floating point numbers to a Date.

Also, you need to add code to manage the case where customfield_21011 is empty.

This code will consider an empty customfield_21011 field as 0:

new Date() + (int)(issue.get("customfield_21011") ?: 0) + 7

 

Like Martin Heini likes this
Martin Heini
Contributor
April 12, 2024

Hi David

Yes, that's the solution I was looking for. Thank so much.

Martin

0 votes
Dick
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 11, 2024

try smart values? 
{{issue.customfield_21011}}

Dick
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 11, 2024
Martin Heini
Contributor
April 12, 2024

Hi Dick

I tried {{...}} without succsess. 
As I understand setContextVar, it is a variable set in a certain context. Here I was looking for a variable that the user can set freely via a screen.
Thanks anyway.

Martin

Like Dick likes this

Suggest an answer

Log in or Sign up to answer