• Re: Sequence Javascript Help

# Sequence Javascript Help

Explorer ,
Jun 23, 2021 Jun 23, 2021

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.

TOPICS
JavaScript , PDF forms

Views

792

Likes

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
9 Replies 9
Engaged ,
Jun 23, 2021 Jun 23, 2021

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("");
var modeleRegEx=/^([1-9]|[1-7][0-9]|8[0-4])?\$/;
event.rc=modeleRegEx.test(testeChaine);
} else {
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

Likes

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Explorer ,
Jun 23, 2021 Jun 23, 2021

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

Likes

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Engaged ,
Jun 23, 2021 Jun 23, 2021

Copied

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

Likes

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Explorer ,
Jun 23, 2021 Jun 23, 2021

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.

Likes

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Explorer ,
Jun 23, 2021 Jun 23, 2021

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.

Likes

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Engaged ,
Jun 23, 2021 Jun 23, 2021

Copied

Ok, I will take care tomorrow.

@+

Likes

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Engaged ,
Jun 24, 2021 Jun 24, 2021

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.
@+

Likes

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Explorer ,
Jun 24, 2021 Jun 24, 2021

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.

Likes

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Engaged ,
Jun 24, 2021 Jun 24, 2021

Copied

LATEST

It's a document level script:

Likes

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Resources