Hi,
I have a date field(cr2d2_approvedon) on power portal form , I tried setting its value to todays date using $('#cr2d2_approvedon_datepicker_description') .val(new Date().toLocaleDateString()) and
$('#cr2d2_approvedon') .val(new Date().toLocaleDateString())
,but when I submit the form , the cr2d2_approvedon column is showing empty in dataverse, Can anyone please help me with this.
Date is a 'complex' field as it also accommodates the datepicker, you will probably find setting a default date in the DatePicker control will give you what you want - the following JavaScript snippet should give you enough details to work out how to set to Today (note: the snippet would be placed inside a JQuery document.ready):
// set a default date to a specific date
$("#your_fieldname") // input control
.next() // the date picker container
.data("DateTimePicker") // the date picker object
.defaultDate(new Date("2020-01-01"));
This link also has some other datepicker operations https://powerusers.microsoft.com/t5/General-Discussions/Date-Picker-modified-through-javascript-fails-required-field/m-p/1938281/highlight/true#M1917
Edit: user form Metadata records if wanting to capture a date when a record was updated or created (where the out of the box created on or modified on is not sufficient).
Hi @PPBeginner ,
Are you setting this Date on creation of record? If yes, then instead of using JavaScript you should use form metadata to set values at the time of creation.
Please share if there are any concerns.
Thanks,
Saud
If you like this post, give a Thumbs up. Where it solved your request, Mark it as a Solution to enable other users find it.
WarrenBelz
9
Most Valuable Professional
Fubar
6
Super User 2025 Season 1
Rondel
6