How to get difference between Start Date and End Date when they're on 2 different forms

Discussions about Forms Designer for SharePoint 2013 / 2016 and Office 365.
Locked
Jdubs
Posts: 73
Joined: Fri Dec 19, 2014

23 Dec 2014

On New Form, I calculate the Start Time by startTime = new Date ();

On Edit Form, the end-user chooses a date for End Date, and on that field .change I want to calculate End Time by endTime = new Date();


Question: How do I access the startTime variable that was created on the New Form so that I can do the following on the Edit Form: startTime - endTime?


When these 2 variables are on the same form, I'm able to get the difference and output seconds/hours/days/etc. to my hearts content. But because they're on 2 separate forms, if I re-calculate the startTime it won't pick up the time that was originally on the new form.


I've tried outputting the startTime variable to a SharePoint field and do the following: fd.field('StartTime').value() - endTime, but I come back with a NaN.


Thank you.

Jdubs
Posts: 73
Joined: Fri Dec 19, 2014

23 Dec 2014

Would love an answer for this. Here's as close as I've gotten so far:


I get the Date object, convert it to milliseconds, and store it in a variable and a SharePoint field:

New Form


var calcStartDate = new Date();

var cStartTime = calcStartDate.valueOf();

fd.field('calcStartTime').value(cStartTime);


Edit Form

var calcEndDate = new Date();

var cEndTime = calcEndDate.valueOf();

fd.field('calcEndTime').value(cEndTime);


From here, I can calculate the difference using SharePoint, but cannot calculate using Forms Designer/JavaScript.


Doesn't Work

var cTotalTime = cEndTime - cStartTime;

fd.field('calcEndTime').value(cTotalTime);

In SharePoint, the value of the field "calcEndTime" = NaN


Does Work


In SharePoint, I create a calculated field called "tTotalTime" that = [calcEndTime] - [calcStartTime].

When calcEndTime is populated, in SharePoint "tTotalTime" = 1,334,535 (in milliseconds).


What am I doing wrong? Thank you!

User avatar
Dmitry Kozlov
Site Admin
Posts: 1524
Joined: Thu Jun 07, 2012

24 Dec 2014

Hi,

Could you drop HTML-source of your Edit form with your code in there to support@spform.com?

Jdubs
Posts: 73
Joined: Fri Dec 19, 2014

26 Dec 2014

Sure! How do I do that?

User avatar
Dmitry Kozlov
Site Admin
Posts: 1524
Joined: Thu Jun 07, 2012

29 Dec 2014

Just open your customized form in the browser, right-click anywhere on the form, select 'View source' menu item, copy and paste the contents into a text file and send it to support@spform.com.

Jdubs
Posts: 73
Joined: Fri Dec 19, 2014

29 Dec 2014

Done.

I'm still using SharePoint's "calculated" field for this calculation currently.


Thanks so much!

User avatar
Dmitry Kozlov
Site Admin
Posts: 1524
Joined: Thu Jun 07, 2012

30 Dec 2014

Please, use the following code to calculate difference between two numbers via JavaScript:

Code: Select all

var calcStartTime = parseInt(fd.field('calcStartTime').value().replace(/,/g, ''));
var calcEndTime = parseInt(fd.field('calcEndTime').value().replace(/,/g, ''));
var cTotalTime = cEndTime - cStartTime;

Locked
  • Information
  • Who is online

    Users browsing this forum: No registered users and 7 guests