Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

Subtraction of time (AEM Forms)

rakeshk21205956
Level 3
Level 3

I have made a form in which there is a table of 30 rows  with INTIME and OUTTIME(2 sets in single row)  with a cell in which it calculates the difference of time between INTIME and OUTTIME.....everything is working fine except for whenever there is  08 or 09 in minutes  then either there is no calculation or it outputs the same minutes without calculations .  see the screenshot.. :  when 08 or 09 is in outtime it shows either no calculation or wrong calculation and when 08 or 09 is in intime it show the minutes of the outtime. 

 

Attached is the link to the original file... problem is when there is 08 or 09 in minutes  apart from that script is working fine.. script is in variable  and called from exit event of outtime.

https://www.dropbox.com/s/7vaz0cjb12uef4e/Time%20Calculation.pdf?dl=0

 

 

 Time calculation.png

@try67   @Kosta_Prokopiu1 

1 Accepted Solution
Kosta_Prokopiu1
Correct answer by
Employee
Employee

ok, this is going to be the last one now - I have a dayjob 🙂

Adapt this draft approach to your solution.

To sum up I did a quick hack by creating a further function in the script object and call it in the exit event of the out-times.

function sumResults(rootSomResults, resultFieldName)
{
  var results = xfa.resolveNodes(rootSomResults+"[*]"+"."+resultFieldName);
  var sumMinutes = 0;
  for (i=0; i < results.length; i++) {
    var resultTime = results.item(i).rawValue;
    if (resultTime != null) {
      var timeFields = resultTime.split(":");
      sumMinutes = sumMinutes + (Number(timeFields[0])*60) + Number(timeFields[1]);
    }
  }
  var hours = Math.floor(sumMinutes/60);
  var minutes = sumMinutes%60
  return String(hours)+":"+String(minutes);
}

 

Add a line to the exit events:

TextField1.rawValue = calcTimes.sumResults("Table1.Row","result")

Where p1 is the row SOM and p2 is the name of your result field.

kprokopi_0-1595259397815.png

TextField1 is the name of an additional text field where the result is to go

kprokopi_1-1595259480159.png

 

kprokopi_2-1595259647972.png

 

View solution in original post

0 Replies
rakeshk21205956
Level 3
Level 3
Also want to Add all the result at the bottom, how to do that
rakeshk21205956
Level 3
Level 3
Problem got solved.......... only issue left is how to add all the result at the bottom of the table
Kosta_Prokopiu1
Correct answer by
Employee
Employee

ok, this is going to be the last one now - I have a dayjob 🙂

Adapt this draft approach to your solution.

To sum up I did a quick hack by creating a further function in the script object and call it in the exit event of the out-times.

function sumResults(rootSomResults, resultFieldName)
{
  var results = xfa.resolveNodes(rootSomResults+"[*]"+"."+resultFieldName);
  var sumMinutes = 0;
  for (i=0; i < results.length; i++) {
    var resultTime = results.item(i).rawValue;
    if (resultTime != null) {
      var timeFields = resultTime.split(":");
      sumMinutes = sumMinutes + (Number(timeFields[0])*60) + Number(timeFields[1]);
    }
  }
  var hours = Math.floor(sumMinutes/60);
  var minutes = sumMinutes%60
  return String(hours)+":"+String(minutes);
}

 

Add a line to the exit events:

TextField1.rawValue = calcTimes.sumResults("Table1.Row","result")

Where p1 is the row SOM and p2 is the name of your result field.

kprokopi_0-1595259397815.png

TextField1 is the name of an additional text field where the result is to go

kprokopi_1-1595259480159.png

 

kprokopi_2-1595259647972.png

 

View solution in original post

rakeshk21205956
Level 3
Level 3
Thanks for the script but somehow i am not able to figure out where to put the script
Kosta_Prokopiu1
Employee
Employee
In the script object that I provided in my previous examples? Did you use my other approaches? If so then put it at the end of the script object and call it in the exit event. You need to adjust things to your form implementation - I cannot do everything....