Skip to main content
FormNewbie
Participating Frequently
June 23, 2021
Question

Sequence Javascript Help

  • June 23, 2021
  • 1 reply
  • 3553 views

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.

This topic has been closed for replies.

1 reply

bebarth
Community Expert
Community Expert
June 23, 2021

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

FormNewbie
Participating Frequently
June 23, 2021

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

bebarth
Community Expert
Community Expert
June 23, 2021

up to 12 months or 12 Months + 2W + Daily?