flag true/false depending on two field value

madalinus1
Tera Contributor

Hello, I dont' kow if I write in correct location but I will try:

I need some help for this: 

When the user field changes, we will check whether the customer has visited the store at least once during the previous week and made a purchase; in this case, we will set the flag to true.

I created the form and the field names are the following:

user field: (user)
entry date ( entry_date )
flag: (already_customer)

 

madalinus1_0-1704995144256.png

 

 

if the user it's alredy present with a date oldest than 7 days, the field ( already_customer ) will change to true.

How I can do it with a onChange client script? 

7 REPLIES 7

Anand Kumar P
Giga Patron
Giga Patron

Hi @madalinus1,

You can write onchange client script on user field and use below script.

var currentDate = new GlideDateTime();

var entryDate = g_form.getValue('entry_date');

if (entryDate) {
var parsedEntryDate = new GlideDateTime(entryDate);

var daysDifference = GlideDateTime.subtract(currentDate, parsedEntryDate).getDayPart();

if (daysDifference <= 7) {
g_form.setValue('already_customer', true);
} else {
g_form.setValue('already_customer', false);
}

}
Mark it as helpful and solution proposed if it serves your purpose.
Thanks,
Anand

 

Hi,

thanks a lot for the help, I tryed but I recive the following error: 

madalinus1_0-1704996871620.png

 

Hi @madalinus1,

Try using only date

var currentDate = new Date();

Mark it as helpful and solution proposed if it serves your purpose.
Thanks,
Anand

 

And, instead of 'getDayPart'?

madalinus1_0-1704998611023.png