Copy link to clipboard
Copied
I have a sequence that I'd like to use to get the following answers on, but not sure how to write it in Javascript, see below:
Daily(D) = 1,2
1 Week = 3,4,5,6,7
1 Weekly + Daily = 8,9
2 Weekly = 10,11,12,13,14
2 Weekly + Daily = 15,16
1 Month = 17,18,19,20,21,22,23,24,25,26,27,28
1 Month + Daily = 29 & 30
1 Month + 1 Week = 31,32,33,34,35
1 Month + 1 Week + Daily = 36,37
1 Month + 2 Weeks = 38,39,40,41,42
1 Month + 2 Weeks + Daily = 43, 44
2 Months = 45,46,47,48,49,50,51,52,53,54,55,56
2 Months + Daily = 57,58
2 Months + 1W = 59,60,61,62,63
2 Months + 1W + Daily = 64, 65
2 Months + 2W = 66,67,68,69,70
2 Months + 2W + Daily = 71, 72
3 Months = 73,74,75,76,77,78,79,80,81,82,83,84
For example, if the days are equal to 57, then we would want to split the following into 2 Months and 1 Day. Or if the field is equal to 64, then it would split into 2 months 1 week and 1 day.
Copy link to clipboard
Copied
Hi,
In custom keystorke script:
if(!event.willCommit) {
var aTester=event.value.split("");
aTester.splice(event.selStart, event.selEnd-event.selStart, event.change);
var testeChaine=aTester.join("");
// Teste de validitƩ de la touche entrƩe
var modeleRegEx=/^([1-9]|[1-7][0-9]|8[0-4])?$/;
event.rc=modeleRegEx.test(testeChaine);
} else {
// Teste de validitƩ de l'entrƩe globale
var modeleRegEx=/^\d{0,2}$/;
event.rc=event.value=="" || modeleRegEx.test(event.value);
}
And in custom validation script:
if (event.value=="") event.value="";
else if (event.value<3) event.value="Daily(D)";
else if (event.value<8) event.value="1 Week";
else if (event.value<10) event.value=" Weekly + Daily";
else if (event.value<15) event.value="2 Weekly";
else if (event.value<17) event.value="2 Weekly + Daily";
else if (event.value<29) event.value="1 Month";
else if (event.value<31) event.value="1 Month + Daily";
else if (event.value<36) event.value="1 Month + 1 Week";
else if (event.value<38) event.value="1 Month + 1 Week + Daily";
else if (event.value<43) event.value="1 Month + 2 Weeks";
else if (event.value<45) event.value="1 Month + 2 Weeks + Daily";
else if (event.value<57) event.value="2 Months";
else if (event.value<59) event.value="Months + Daily";
else if (event.value<64) event.value="2 Months + 1W";
else if (event.value<66) event.value="Months + 1W + Daily";
else if (event.value<71) event.value="Months + 2W";
else if (event.value<73) event.value="2 Months + 2W + Daily";
else event.value="3 Months";
ro
Copy link to clipboard
Copied
Close, but I want to be able to go into a 12 month cycle instead of being limited to the 3 months. It seems as though there is a sequence to the equation, but I cannot for the life of me figure it out. Seems to be 2, then 5, then 5+2, then 5*2... etc. Is there an equation that can allow me to use this methodology instead of a series of if/then statements? And also if the days are passed 100+ how to account for that.
Thank you
Copy link to clipboard
Copied
up to 12 months or 12 Months + 2W + Daily?
Copy link to clipboard
Copied
12 Months + 2W + Daily. The calculation is based on a date range so to get the = # you would need to do 6/23-6/30 = 8 (days) which would be 1 Week 1 Day.
Copy link to clipboard
Copied
Also my output would be three separate boxes. One for Months, one for weeks and one for days because they are multiplied by a specific $ amount.
Copy link to clipboard
Copied
Ok, I will take care tomorrow.
@+
Copy link to clipboard
Copied
Not obvious to define the modulo (frequency) resulting of the difference between the 2 dates but I think I've got it.
As you mentioned, I limited de difference between 2 dates for a result of 12 Months 2 Weeks and 1 Day (so <353 days).
I did some successful tests between 1 and 84 days and I let you do more other one.
Let me know if you find some mistakes and which ones.
@+
Copy link to clipboard
Copied
This looks great so far, but where are you storing your javascript? I checked within the properties of the fields but did not see any javascript written there.
Copy link to clipboard
Copied
It's a document level script: