• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Unable to show date difference

Explorer ,
Oct 28, 2020 Oct 28, 2020

Copy link to clipboard

Copied

I have prepared a test form in which there are two date fields, namely "dt_start" and "dt_end" formatted as "dd-mmm-yy". Now I would like to show the date difference in another text field named "txt_dateDiff". I have added the following javascript codes in custom calculation field:

 // Get the input field values
var s1 = getField("dt_start").valueAsString;
var s2 = getField("dt_end").valueAsString;


if (s1 && s2) {// Convert date strings to date objects
var d1 = util.scand("mm/dd/yyyy", s1);
var d2 = util.scand("mm/dd/yyyy", s2);

// Set this field value to the difference in days
// 864e5 = 86400000 = 1000 * 60 * 60 * 24 = number of milliseconds in a day
event.value = Math.abs(Math.round((d2 - d1)/864e5));

} else {
// Alert user
event.value = "Enter both date";
}

But unfortunately, nothing is shown on the text field, even no alert (Enter both date) is there. I have uploaded the test pdf to cloud and attaching the link here with this my post for your convenience.

https://www.dropbox.com/s/uhore9dhut7ykh4/testform.pdf?dl=0 

Please let me know where the problem is.

TOPICS
Create PDFs , How to , PDF forms

Views

547

Translate

Translate

Report

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

Copy link to clipboard

Copied

Why does you use in the script a different date format?

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

I found this code by googling and thought this date format is not the data source date format, this format is the output date (date which will be shown in the text field) format. I might be wrong. Do you think, changing this format (mm/dd/yyyy) will resolve the issue? Please see my link where I have uploaded a copy of the form. You may kindly check the code there as well.

 

Thanks

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

Try it out.

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

Tried but no improvement. I have updated the pdf form according to your suggestion. Here is the updated link:

https://www.dropbox.com/s/8m6dqhtvigljpbw/testform.pdf?dl=0 

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

There are errors in your code. Check the JS Console...

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

There was no error except no "this". But still no solution after using "this" infront of "getField". Any idea?

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

There is most certainly an error:

 

try67_0-1603973800495.png

 

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

Please tell me what is the solution. I have little knowledge about debugging!

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

Change the incorrect field names you used in your code.

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

LATEST

I somehow resolved the problem but don't know what was the problem, really! The field names were not the problem although I have changed it to "dt_s" and "dt_e" later. Very peculiar.

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

You must use the correct names of the fields:

Bild1.jpg

Votes

Translate

Translate

Report

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