flag true/false depending on two field value
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-11-2024 09:45 AM
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)
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-11-2024 09:54 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-11-2024 10:14 AM
Hi,
thanks a lot for the help, I tryed but I recive the following error:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-11-2024 10:31 AM
Hi @madalinus1,
Try using only date
var currentDate = new Date();
Mark it as helpful and solution proposed if it serves your purpose.
Thanks,
Anand
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-11-2024 10:43 AM
And, instead of 'getDayPart'?