Set Date and Time value to current date and time
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();
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();
- Dmitry Kozlov
- Site Admin
- Posts: 1524
- Joined: Thu Jun 07, 2012
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.
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.
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.
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.
- Dmitry Kozlov
- Site Admin
- Posts: 1524
- Joined: Thu Jun 07, 2012
There're no tokens or reserved words. It's pure JavaScript. Please, try this:
Also, I'd recommend you to read the post:
https://spform.com/javascript-framework ... ime-fields
Code: Select all
fd.field('Time_x002d_Out').value(new Date());
https://spform.com/javascript-framework ... ime-fields
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]);
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]);
- Dmitry Kozlov
- Site Admin
- Posts: 1524
- Joined: Thu Jun 07, 2012
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.
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
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
- Dmitry Kozlov
- Site Admin
- Posts: 1524
- Joined: Thu Jun 07, 2012
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:
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());
-
- Information
-
Who is online
Users browsing this forum: No registered users and 3 guests