Forums

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

Date Validator Script

Didem Seda Taş April 11, 2022

Hi there,

I'm new to scripting so I'll ask for your help often :)

 

I have two fields named "Hedeflenen Tamamlanma Tarihi" and "DA Onay Tarihi".

The user needs to fill in the "Hedeflenen Tamamlanma Tarihi" field first and then the "DA Onay Tarihi" field.

My request is:
When the user selects "DA Onay Tarihi" before the "Hedeflenen Tamamlanma Tarihi", the "DA Onay Tarihi Hedeflenen Tamamlanma Tarihinden önce olmalıdır." I want a warning.

 

Example;

If the Hedeflenen Tamamlanma Tarihi: 01.01.2022 is selected and the user chooses the DA Onay Tarihi as 03.01.2022, I want it to give an error.

 

Could you please help me?

Have a nice day :)

1 answer

1 accepted

1 vote
Answer accepted
PD Sheehan
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.
April 11, 2022

If you want to do this in a Workflow Validator (as implied by your tags), you can easily do this with a simple scripted validator.

def date1 = cfValues['DA Onay Tarihi']
def date2 = cfValues['Hedeflenen Tamamlanma Tarihi']
date2 >= date1

When the simple scripted validator returns true, then nothing happens. When it returns false, it will display the warning of your choosing. The warning and the placement of the warning can be entered in the simple scripted validator configuration screen.

Didem Seda Taş April 11, 2022

image (16).png

I placed the same script you wrote in the stream as a simple script validator. What is the reason for the errors that appear?

PD Sheehan
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.
April 11, 2022

Hover over the underlined text and it will tell you. Perhaps the field name is incorrectly spelled for the first field.

Then the comparison can't be confirmed to be correct since the code checker doesn't know what value will be returned from a field that it doesn't recognize.

Didem Seda Taş April 11, 2022

It's giving an error because there are 2 fields with the same name.


Now it gives an error when I choose the right date. Could it be that the 'DA Approval Date' field type is a date time picker, and the 'Target Completion Date' field type is a date picker?

Didem Seda Taş April 11, 2022

Hi Peter, I edited the fields and ran your code again and it worked.

Thank you very much for your help :)

Suggest an answer

Log in or Sign up to answer