I want to set a date/time field to the current systems dated & time when a user checks a Yes/No field. For example, "[Yes] - Equipment was collected" set the PickUpDate Field (Date/Time) with the current system date. I am not a developer so I am looking for a simply solution
- Created a button(Check box in your case) on the form, with the action of 'JavaScript'
- Given the date/time control a Client ID
- Created the following function within the 'Custom JavaScript' section in Form Settings:
- function setDateTime()
- {
- var fullDate = new Date()
- var twoDigitMonth = ("0" + (fullDate.getMonth() + 1)).slice(-2)
- var hours = fullDate.getHours();
- var minutes = fullDate.getMinutes();
- var currentDate = fullDate.getDate() + "/" + twoDigitMonth + "/" + fullDate.getFullYear();
- if (hours < 10) { hours = "0" + hours; }
- /** Round down to the nearest 5 minutes. This is due to us rounding the minutes but not the hours. For example, 09:58 could be rounded up to 09:60 (invalid). Instead, 09:58 becomes 09:55.
- **/
- minutes = minutes - 2.5;
- minutes = 5 * Math.round( minutes / 5 );
- // Set the date field
- NWF$('#' + fldDateClosed).val(currentDate);
- // Set the time (hours + minutes) fields
- NWF$('#' + fldDateClosed + ' + IMG + SELECT').val(hours);
- NWF$('#' + fldDateClosed + ' + IMG + SELECT + SELECT').val(minutes);
- // Set Incident Status
- NWF$('#' + fldStatus).val('Completed');
- }
Upon previewing, and clicking the 'Now' button on the form, it fills the input with the following:
Here is how to modify the hours and minutes on the form?
Here is a sample to set time to 10 AM : 45
NWF$('#' + fldDate + " + IMG + SELECT").val('10 AM');
NWF$('#' + fldDate + " + IMG + SELECT + SELECT").val('45');
Regards
Thanks for this....I will try it. It seems a lot of work just to get a default date....but thank you
Another way to do this could be to have a simple single line of text field, with the "Common" variables of Current Date / Current Time. If you want it to fit into a date / time field, you'd need to run a workflow after the form is submitted in order to convert that to a date / time field. I'm not sure how simple it would be to convert it to a date / time field from a single line of text, but since it'd be in "computer speak", probably not too hard.
If you just need the date that the checkbox was checked, you could instead run a workflow when the form is submitted - and, if "Yes" is checked, the workflow could populate that field for you. I believe that simple workflows (under 5 actions) are now free, too, so this wouldn't hit that. Conditional run, get current date / time, update field, save!
The problem is, I need to set this date during the completion of the form. Using InfoPath, you can run rules to set fields, etc., before the form is submitted.
Just stumbled across this trying to achieve the same thing, Its an old post however thought I'd share the solution.
To capture the "current date" that an item is closed and to prevent the date being recorded if the action is left open I used an a calculated value for the "Date Closed" field.
|
Hi
Please check this
https://community.nintex.com/thread/16781-calculate-date-based-on-another-date
Thanks
Bashya Rajan
Reply
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.