JMWE or some other tool: disallow past date in date custom field End of project

Jurica Petricevic
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.
October 21, 2021

Hi Community,

 

i found several similar topics but none gave a clear answer.

Is it possible to do this with the help of any tool that we have in the house. JMWE, ScriptRunner or automation?

 

Best regards

Jurica Petricevic

2 answers

2 accepted

1 vote
Answer accepted
Sayed Bares {Appfire} October 21, 2021

Hi Jurica,

If you wanna do this with JMWE, you can easily implement it with Scripted (Groovy) Validator. Once you have added the validator set its parameters as followed:

Groovy script:

issue.get("customfield_10600")!=null && issue.get("customfield_10600")>=now

Error message:

The field "End of Project" must be precisely defined. Check your entry once again

For field:

End of project
screenshot-localhost_8080-2021.10.21-17_56_04.png
Note: it is recommended to use custom field IDs instead of names because upon changing field names you will have to change your validator but by using IDs you won't have to.
Hope it helps.
Jurica Petricevic
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.
October 21, 2021

@Sayed Bares {Appfire} Thank you for your answer.

I have one more question here. Is it possible at this point to make a connection to the Fixtermin field?

In front of the End of Project field there is a fixtermin field to which the standard answer is No. If No in that field, it is necessary to allow any values, including the entry of an empty end of project field.

if in the field Fixtermin Yes then it is necessary to use the mentioned script where the value in the fields End of project may be the same or greater than today.

Do you have any suggestions here?

Best regards

Jurica Petricevic

Sayed Bares {Appfire} October 21, 2021

Hi Jurica,

You can use the following code for your use case:

if (issue.get("customfield_10700")!=null && issue.get("customfield_10700")=="Yes"){
issue.get("customfield_10600")!=null && issue.get("customfield_10600")>=now
}
else true

 customfield_10700 is the ID of fixtermin field and customfield_10600 is the ID of End of Project field.

result.png

You can also use the following code which does the same thing but just in one line:

issue.get("customfield_10700")!=null && issue.get("customfield_10700")=="Yes"? issue.get("customfield_10600")!=null && issue.get("customfield_10600")>=now : true

Hope it helps and let us know how it goes.

Like Cesar Duran likes this
Jurica Petricevic
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.
October 21, 2021

@Sayed Bares {Appfire} great job. the only problem i have is that Fixtermin yes option selected does not allow me today's date. This was possible in the first script.

Can you understand why?

Thx a lot mate.

 

Bets regards

Jurica

Like Sayed Bares {Appfire} likes this
Sayed Bares {Appfire} October 22, 2021

Hi Jurica,

Glad it is working now and you are most welcome :)

To fix todays issue please use the following code:

issue.get("customfield_10700")!=null && issue.get("customfield_10700")=="Yes"? issue.get("customfield_10600")!=null && issue.get("customfield_10600")>=today : true

or the following code which is much shorter and easier to implement:

issue.get("customfield_10700")!="Yes" || (issue.get("customfield_10600")!=null && issue.get("customfield_10600")>=today)

Let me know if you have any further questions or concerns.

Best,

Sayed

0 votes
Answer accepted
Jurica Petricevic
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.
October 21, 2021

It was solved with 

Simple scripted validator (script Runner)

 

Condition:

Date now = new Date()
cfValues['End of project'] >= new Date(now.getYear(), now.getMonth(), now.getDate())

 

Error Message:

The field "End od Project" must be precisely defined. Check your entry once again.

 

Field:

End of project

Suggest an answer

Log in or Sign up to answer