Update Date Field automatically

Discussions about Forms Designer for SharePoint 2013 / 2016 and Office 365.
Locked
TWendt
Posts: 109
Joined: Mon Sep 08, 2014

28 May 2018

Hi all,
is it possible to update the Kendo Date Time field automatically. I mean, i have a start date and time. When i switch to the due date field, the field should update from the start date field.

Best wishes
Tom :?:

User avatar
Nikita Kurguzov
Posts: 889
Joined: Mon Jul 03, 2017

28 May 2018

Dear Tom,
Yes, of course! Please, check out the following article - https://spform.com/javascript-framework ... eld-values
It shows you how to detect change in any of the fields, how to get the current value and how to set a new value to a field. All you need to do, is write the code to detect change in a field Start Date and to update the Due Date properly.

For example:

Code: Select all

fd.field('StartDate').change(function(){
  var startDate = fd.field('StartDate').control('getDate');
  var dueDate = new Date();
  var weekInMilliseconds = 7 * 24 * 60 * 60 * 1000;
  dueDate.setTime(startDate.getTime() + weekInMilliseconds);
  fd.field('DueDate').value(dueDate);
});
Cheers

TWendt
Posts: 109
Joined: Mon Sep 08, 2014

28 May 2018

Hi Nikita,

do you have an example for me?

Best wishes
Tom

User avatar
Nikita Kurguzov
Posts: 889
Joined: Mon Jul 03, 2017

28 May 2018

Dear Tom,
Yes, I was just testing it out for you, it's in my first reply now. Check it out, but don't forget to replace StartDate and DueDate with correct InternalNames of the fields, I do not know them, but you can check them in the designer, when you select a field. Also, I am adding a week, but you can add any amount of days instead.
Cheers

TWendt
Posts: 109
Joined: Mon Sep 08, 2014

16 Oct 2018

Sorry for the late delay,
the script doesn't work.
Here is my script

fd.field('Anfangsdatum').change(function(){
var startDate = fd.field('Anfangsdatum').control('getDate');
var dueDate = new Date();
var weekInMilliseconds = 7 * 24 * 60 * 60 * 1000;
dueDate.setTime(startDate.getTime() + weekInMilliseconds);
fd.field('Fälligkeitsdatum').value(dueDate);
});

Best wishes
Tom

User avatar
AlexZver
Posts: 232
Joined: Mon Aug 27, 2018

17 Oct 2018

Hi Tom,

The example was for the DateTime field with a default template.
A code for the field with a Kendo template (your choice, as I understand) will be slightly different:

Code: Select all

fd.field('Anfangsdatum').change(function(){
    var startDate = fd.field('Anfangsdatum').value();
    var dueDate = new Date(); 
    var weekInMilliseconds = 7 * 24 * 60 * 60 * 1000;
    dueDate.setTime(startDate.getTime() + weekInMilliseconds);
    fd.field('Fälligkeitsdatum').value(dueDate);
});

Cassidy
Posts: 1
Joined: Thu Oct 25, 2018

01 Nov 2018

Hi Alex, so this specific code will only work with a Kendo template and no other?

User avatar
Nikita Kurguzov
Posts: 889
Joined: Mon Jul 03, 2017

01 Nov 2018

Dear Cassidy,
Use the following code for default Date field:

Code: Select all

fd.field('StartDate').change(function(){
  var startDate = fd.field('StartDate').control('getDate');
  var dueDate = new Date();
  var weekInMilliseconds = 7 * 24 * 60 * 60 * 1000;
  dueDate.setTime(startDate.getTime() + weekInMilliseconds);
  fd.field('DueDate').value(dueDate);
});
And the following code for Kendo Date field:

Code: Select all

fd.field('StartDate').change(function(){
    var startDate = fd.field('StartDate').value();
    var dueDate = new Date(); 
    var weekInMilliseconds = 7 * 24 * 60 * 60 * 1000;
    dueDate.setTime(startDate.getTime() + weekInMilliseconds);
    fd.field('DueDate').value(dueDate);
});
I hope this will help you, as these are the only two options for date fields available in Forms Designer by default. If you have any questions - let us know!
Cheers

Locked
  • Information
  • Who is online

    Users browsing this forum: No registered users and 23 guests