Salir
  • Comunidad global
    • Idioma:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티

Days extrapolated or manually entered based on a pulldown selection.

Colaborador ,
Nov 21, 2022 Nov 21, 2022

Aaaannnndd, I'm back.  The "bright idea fairy" has visited after finally working out a headache, presenting the solution -- being rather proud of it -- and now just in time for the brass to ask me to add another quirk.  I am totally lost and, yet again, find myself turning to the SME's here for another assist.  If any of y'all find yourself in the NOVA area, I absolutely owe you a drink at a minimum. :S

So, here's the situation.  I have five (5) fields.

1) Absence Date From:  Field Name "Date_Absence_From"

2) Absence Date To:   Field Name "Date_Absence_To"

3) Total Days Authorized:  Field Name "Authorized_Days"

4) Unauthorized or Gapped:  Field Name "UAorGapped"

5) Total Days UA/Gapped:  Field Name "Total_Days_UAorGapped"

 

After entereing in the date in fields 1 and 2, field 4 currently consists of a pulldown with "N/A", "Unauthorized", or "Gapped" as selections.  If N/A (default) is selected, the number of days auto-calculates in field 3.  If "Unauthorized" or "Gapped" is selected, the number of days auto-calculates in Field 5. 

 

They are now asking for a "Blended" selection in the pulldown (Field 4) that will allow them to manually enter a number in Field 3 when "Blended" is selected which will then auto-calculate the remaining number of days in Field 5.  I've tried thinking this through and working it out to no avail.  This one is so waaayyyy beyond me, my head hurts.  And again, my sincerest thanks in advance for any and all assistance.

 

The scripts in place are as follows:

Field 4 Validation Script:
event.value=="N/A";
this.getField("Total_Days_UAorGapped").value = "N/A";
event.value== ("Unauthorized","Gapped");
this.getField("Total_Days_UAorGapped").value = "";
var sDate1 = this.getField("Date_Absence_From").value;
var sDate2 = this.getField("Date_Absence_To").value;
var oDate1 = util.scand("dd mmm yy", sDate1);
var oDate2 = util.scand("dd mmm yy", sDate2);
var nDay = 1000 * 60 * 60 * 24;
var eDays = Math.abs(1+((oDate2-oDate1)/nDay));
var eDaysP = Math.abs(((oDate2-oDate1)/nDay));
var eDaysN = Math.abs(((oDate1-oDate2)/nDay));
if ((sDate1 && sDate2) && (sDate2 > sDate1)) {
event.value = Math.round(eDaysP);
} else if ((sDate1 && sDate2) && (sDate1 > sDate2)) {
event.value = Math.round(eDaysN) *1;
}

 

Field 3 Custom Calculation Script:

var sDate1 = this.getField("Date_Absence_From").value;
var sDate2 = this.getField("Date_Absence_To").value;
var oDate1 = util.scand("dd mmm yy", sDate1);
var oDate2 = util.scand("dd mmm yy", sDate2);
var nDay = 1000 * 60 * 60 * 24;
var eDays = Math.abs(1+((oDate2-oDate1)/nDay));
var eDaysP = Math.abs(((oDate2-oDate1)/nDay));
var eDaysN = Math.abs(((oDate1-oDate2)/nDay));
if ((sDate1 && sDate2) && (sDate2 > sDate1)) {
event.value = Math.round(eDaysP);
} else if ((sDate1 && sDate2) && (sDate1 > sDate2)) {
event.value = Math.round(eDaysN) *1;
}

var UAG1 = this.getField("UAorGapped").value;
if (UAG1=="N/A") event.value == "";
else if (UAG1=="Unauthorized","Gapped") event.value = "N/A";

 

And

Field 5 Custom Calculation Script:

var sDate1 = this.getField("Date_Absence_From").value;
var sDate2 = this.getField("Date_Absence_To").value;
var oDate1 = util.scand("dd mmm yy", sDate1);
var oDate2 = util.scand("dd mmm yy", sDate2);
var nDay = 1000 * 60 * 60 * 24;
var eDays = Math.abs(1+((oDate2-oDate1)/nDay));
var eDaysP = Math.abs(((oDate2-oDate1)/nDay));
var eDaysN = Math.abs(((oDate1-oDate2)/nDay));
if ((sDate1 && sDate2) && (sDate2 > sDate1)) {
event.value = Math.round(eDaysP);
} else if ((sDate1 && sDate2) && (sDate1 > sDate2)) {
event.value = Math.round(eDaysN) *1;
}

var UAG = this.getField("UAorGapped").value;
if (UAG=="N/A") event.value = "N/A";
else if (UAG=="")event.value = "";



  

TEMAS
JavaScript , Formularios PDF
3.1K
Traducir
Informe
Directrices de la comunidad
Sé amable y respetuoso, muestra títulos de crédito de la fuente de contenido original y busca duplicados antes de publicar. Más información
community guidelines
1 SOLUCIÓN ACEPTADA
Community Expert ,
Nov 21, 2022 Nov 21, 2022

To go back to your question. If you want to allow the user to enter a value manually, do the following to your calculation script:

 

if (this.getField("Field 4").valueAsString!="Blended") {
	// put the rest of your calculation code here
}

Ver la solución en mensaje original publicado

Traducir
Informe
Directrices de la comunidad
Sé amable y respetuoso, muestra títulos de crédito de la fuente de contenido original y busca duplicados antes de publicar. Más información
community guidelines
Community Expert ,
Nov 21, 2022 Nov 21, 2022

Before moving forward with this, you must fix the errors in your current code. Each one of the first 4 lines you posted has an error in it:

 

event.value=="N/A";
thisgetField("Total_Days_UAorGapped").value = "N/A";
event.value== ("Unauthorized","Gapped")
thisgetField("Total_Days_UAorGapped").value = ""

Traducir
Informe
Directrices de la comunidad
Sé amable y respetuoso, muestra títulos de crédito de la fuente de contenido original y busca duplicados antes de publicar. Más información
community guidelines
Colaborador ,
Nov 21, 2022 Nov 21, 2022

That's easy for you to say... other than my failure to add the semi-colons while touchtyping from another computer, as the scripts have been working, I'd be hard pressed to identify what other errors there may be.  A scripting genius, I am not -- nor an amature, nor even a novice. Just a knucklehead attempting to make lemonade from a bag of lemons dumped in my lap. 😉

Traducir
Informe
Directrices de la comunidad
Sé amable y respetuoso, muestra títulos de crédito de la fuente de contenido original y busca duplicados antes de publicar. Más información
community guidelines
Community Expert ,
Nov 21, 2022 Nov 21, 2022

Actually, the lack of semi-colons is not an error. JS is not strict about that. It's a good practice to add them, but it's not necessary. The errors are:

1. The "==" operator is used to compare values, not assign them.

2. "thisgetField" is incorrect and should produce a syntax error when entering the code.

It's: this.getField

3. Same as #1. Also, you can't assign (or compare) two values with a comma between them.

4. Same as #2.

Traducir
Informe
Directrices de la comunidad
Sé amable y respetuoso, muestra títulos de crédito de la fuente de contenido original y busca duplicados antes de publicar. Más información
community guidelines
Colaborador ,
Nov 21, 2022 Nov 21, 2022

I caught the periods between this.getFIeld as I was hitting the enter button... quite clearly I missed those as well when transcribing. :S

Traducir
Informe
Directrices de la comunidad
Sé amable y respetuoso, muestra títulos de crédito de la fuente de contenido original y busca duplicados antes de publicar. Más información
community guidelines
Community Expert ,
Nov 21, 2022 Nov 21, 2022

You should always copy and paste your code, not re-type it.

Traducir
Informe
Directrices de la comunidad
Sé amable y respetuoso, muestra títulos de crédito de la fuente de contenido original y busca duplicados antes de publicar. Más información
community guidelines
Colaborador ,
Nov 21, 2022 Nov 21, 2022

I didn't have the option at the time, I was working off my phone and a tablet w/out my laptop available -- it's hard enough balancing just these when wrangling goats in the barn and there's not enough time to get everything done even with the multi-tasking.

 

 No rest for the wicked! 😉

Traducir
Informe
Directrices de la comunidad
Sé amable y respetuoso, muestra títulos de crédito de la fuente de contenido original y busca duplicados antes de publicar. Más información
community guidelines
Community Expert ,
Nov 21, 2022 Nov 21, 2022

Remember that code is just text... You can always email it to yourself and then copy&paste it here.

 

Good luck with the goats!

Traducir
Informe
Directrices de la comunidad
Sé amable y respetuoso, muestra títulos de crédito de la fuente de contenido original y busca duplicados antes de publicar. Más información
community guidelines
Community Expert ,
Nov 21, 2022 Nov 21, 2022

To go back to your question. If you want to allow the user to enter a value manually, do the following to your calculation script:

 

if (this.getField("Field 4").valueAsString!="Blended") {
	// put the rest of your calculation code here
}
Traducir
Informe
Directrices de la comunidad
Sé amable y respetuoso, muestra títulos de crédito de la fuente de contenido original y busca duplicados antes de publicar. Más información
community guidelines
Colaborador ,
Nov 21, 2022 Nov 21, 2022

Added it to the "Authorized_Days" & "Total_Days_UAorGapped" and it merely displayed the total days in both fields without allowing for user entry.  What did I miss? 

Traducir
Informe
Directrices de la comunidad
Sé amable y respetuoso, muestra títulos de crédito de la fuente de contenido original y busca duplicados antes de publicar. Más información
community guidelines
Colaborador ,
Nov 21, 2022 Nov 21, 2022
MÁS RECIENTES

Thank you.  What you provided worked perfectly, once I stopped wearing my arse for a hat.  Got it working and merely attempting to figure out how to get Field 5 to populate with the remainder of days following a manual entry into Field 3 based on the "Blended" selection.

Traducir
Informe
Directrices de la comunidad
Sé amable y respetuoso, muestra títulos de crédito de la fuente de contenido original y busca duplicados antes de publicar. Más información
community guidelines