Set Date and Time value to current date and time

Discussions about Forms Designer for SharePoint 2013 / 2016 and Office 365.
Locked
Saimurali
Posts: 6
Joined: Tue Jun 13, 2017

13 Jun 2017

Hi,
I am trying to create a button and insert a function to set a date / time field value to current date and time value. Also it should save the form and close it. How can i achieve this?

I see the below code in the documentation section and i modified it and it does not do anything. Please help.

fd.field('DateTime')
.value(['4/21/2012', '11 PM', '35']); // by Array
fd.field('DateTime')
.value(new Date()); // by Date-object

My code
fd.field('Time-Out')
.value(['4/21/2012', '11 PM', '35']); // by Array
fd.field('Time-Out')
.value(new Date([Now])); // by Date-object
Save();

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

14 Jun 2017

Hi,
Looks like you're using an incorrent internal name of the field (Time-Out). Please, find the internal name in the field's properties in Forms Designer and use it in your code.

Saimurali
Posts: 6
Joined: Tue Jun 13, 2017

14 Jun 2017

Hi Dmitry,
How do i find the internal name? Sorry a newbie here.
SM.

Saimurali
Posts: 6
Joined: Tue Jun 13, 2017

14 Jun 2017

Hi Dimitry,
I found the internal name but the reserved command does not work. I used both Today and Now. I created a button called Sign-out and i added the following on click events. Both do not work. But if i put a text or a date directly it works.

fd.field('Time_x002d_Out').value([NOW]);
Save();

or

fd.field('Time_x002d_Out').value([Today]);
Save();

and it also does not Save the value. I have to click save button.

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

15 Jun 2017

There're no tokens or reserved words. It's pure JavaScript. Please, try this:

Code: Select all

fd.field('Time_x002d_Out').value(new Date());
Also, I'd recommend you to read the post:
https://spform.com/javascript-framework ... ime-fields

Saimurali
Posts: 6
Joined: Tue Jun 13, 2017

15 Jun 2017

Hi Dmitry,
Thank You.

So i just use fd.field('Time_x002d_Out').value(new Date()); in the Onlick event or do i need to declar variables, functions etc and then use this line at the end of some javascript? I am not too familiar with javascript.

-Sm

Saimurali
Posts: 6
Joined: Tue Jun 13, 2017

15 Jun 2017

Hi Dmitry,
Thank You very much. I got the Statement to work.

But when the template is Kento Date picker. The changes to the date is NOT being saved in the form. If i change it to Default template it works but the time hour and seconds defaults to the next 5th minute. If the time is 11:39, it saves as 11:40. I am trying to capture the exact Minutes for a process.

Can you also tell me, if i want the date field to default to a system field like Modified date field.

I have something like this and its not working.

fd.field('Time_x002d_Out').value([Last_x0020_Modified]);

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

16 Jun 2017

You're right, SharePoint date and time field does not allow you to set the exact time. If you need just to copy Modified date to another date and time field, use a workflow.

Saimurali
Posts: 6
Joined: Tue Jun 13, 2017

21 Jun 2017

Dmitry,
I have two questions
1) How can I set the Onclick event to set the date and SAVE/Close the form? Right now setting the date works but i have to click on Save button. So hats 2 buttons.
2) Do you know of a Javascript that can set "Any date" field to Modified date field?

Thanks again

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

22 Jun 2017

Hi Saimurali,

1. Please, activate Button feature and insert your code into OnClick property of the Save button control:
https://spform.com/buttons/customizatio ... oint-forms

2. You can assign the exact date and time to Kendo's date and time picker: set Template property of a DateTime field to 'Kendo DateTimePicker':
https://spform.com/custom-fields/proper ... kers-dates

Then run the code below right before saving the form:

Code: Select all

fd.field('DateTimeField').value(new Date());

Locked
  • Information
  • Who is online

    Users browsing this forum: No registered users and 5 guests