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

JS - Time comparison

New Here ,
May 12, 2020 May 12, 2020

Dear All,

as I am not specialist I kindly ask for your support. With my PDF form, which consits of 4 fields I want to track the actual project status based on date comparison (Process on schedule, in delay, finished on schedule, finished with delay). With dropdown (= field â„–1) menu user enters process status: Process NOT complete (export value = 0), Process complete (export value = 1). â†’ Custom calcualtion script:

if (event.value=="1") {
this.getField("Date TODAY").value = util.printd("dd.mm.yyyy",new Date());  // Date, when user pushes dropdown â†’ should not be automatically updated!       

} else if (event.value=="0") {
this.getField("Date TODAY").value = this.getField("Date today").value; // Automatically updated date
}

 

This is not working correctly!!!

--------------------------------------------

Field for date comparison ("Time divergence"):

var v1 = this.getField("Deadline date).valueAsString;
var v2 = this.getField("Date TODAY").valueAsString;
if (v1 && v2) {
var d1 = util.scand("dd.mm.yyyy", v1);
var d2 = util.scand("dd.mm.yyyy", v2);
var diff = Math.round((d1-d2)/86400000);
event.value = diff;
} else event.value = "";

 

 

For some reasons status indication is not working correctly. I would be grateful for any advices / recommendations for correct JV. 

 

TOPICS
PDF forms
626
Translate
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 ,
May 12, 2020 May 12, 2020

Saying "it doesn't work correctly" is not very helpful... What exactly goes wrong with it?

Are there error messages? If so, what do they say?

Does it produce any output at all? If so, what output and how is it not correct?

Please elaborate.

Translate
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
New Here ,
May 12, 2020 May 12, 2020

@try67: Many thanks for your reply.  The problem is, that "DATE TODAY"value, which is the basis for "Time divergence" evalution, is not updated correctly. Accordingly status indication is also not updated correctly. E.g.: Completed on schedule"

 

Based on the dropdown export value "0",  "DATE TODAY" value should be automatically updated with system date. 

Accordingly status indication field is also updated automatically. (E.g. "On schedule" can automatically switch to "Delay" dependend on the system date.)

 

Based on the dropdown export value "1",  "DATE TODAY"value should be updated with date of users dropdown choice "Process complete" (export value = 1).  Accordingly this date is static and should not be automatically updated. Accordingly status indication field should not be updated automatically.(E.g. "Completed on schedule" cannot automatically switch to "Completed with delay" dependend on the system date.)

Translate
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 ,
May 12, 2020 May 12, 2020

It sounds like an issue with the fields calculation order. Make sure that the status field is further down the list than the "divergence" field. Also, remove this line from your code:

this.calculateNow();

Translate
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
New Here ,
May 12, 2020 May 12, 2020

...

Translate
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 ,
May 12, 2020 May 12, 2020

Sorry, I'm not following. Where did you place the code? Can you share the file with us?

Translate
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
New Here ,
May 12, 2020 May 12, 2020

This is the dropdown menu code.

Translate
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
New Here ,
May 12, 2020 May 12, 2020

Complete code of dropdown

 

if (event.value=="1") {
this.getField("Date TODAY").value = util.printd("dd.mm.yyyy",new Date());  // Date, when user pushes dropdown â†’ should not be automatically updated!       

} else if (event.value=="0") {
this.getField("Date TODAY").value = this.getField("Date today").value; // Automatically updated date
}

Translate
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 ,
May 12, 2020 May 12, 2020

That won't work. The "Date TODAY" field will not update automatically with the current system date if you do it like that. In order for that to happen you will need to add a doc-level script that changes the field's value each time the file is opened. Something like this:

 

if (this.getField("dropdown").value=="1") this.getField("Date TODAY").value = util.printd("dd.mm.yyyy",new Date());

 

(I don't know the name of the drop-down field, so I just used "dropdown"...)

Translate
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
New Here ,
May 12, 2020 May 12, 2020
LATEST

Date is updating with the current system date for dropdown event value =1 . Thats the problem. It should not be updated automatically as user set process completed status.

 

if (event.value=="1") {
this.getField("Date TODAY").value = util.printd("dd.mm.yyyy",new Date());  // Date, when user pushes dropdown â†’ should not be automatically updated!       

} else if (event.value=="0") {
this.getField("Date TODAY").value = this.getField("Date today").value; // Automatically updated date
}

Translate
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
New Here ,
May 12, 2020 May 12, 2020

Dear try67,

many thansk for your advises. I proceeded as described by you before, but unfortunately it is still not correctly working for Process complete (export value = 1), where field for status indication should stay on "Completed on schedule", but switched during PDF opening to "Completed with delay". So this means, that date value is not static and changes based on system date. 

 

Maybe in the b.m. script the util.printd("dd.mm.yyyy",new Date());  is the problem? 

if (event.value=="1") {
this.getField("Date TODAY").value = util.printd("dd.mm.yyyy",new Date()); 

Translate
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