Skip to main content

Notifications

Community site session details

Community site session details

Session Id : 7BD4UQlSwqrFDvebZpmV77
Power Pages - General Discussions
Unanswered

Set date field to todays date using jquery

Like (0) ShareShare
ReportReport
Posted on 25 Jul 2023 17:45:36 by 4

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.

Categories:
  • Fubar Profile Picture
    7,846 Super User 2025 Season 1 on 25 Jul 2023 at 22:04:57
    Re: Set date field to todays date using jquery

    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).

  • Saud Ali Profile Picture
    812 Super User 2024 Season 1 on 25 Jul 2023 at 18:55:44
    Re: Set date field to todays date using jquery

    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.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Understanding Microsoft Agents - Introductory Session

Confused about how agents work across the Microsoft ecosystem? Register today!

Markus Franz – Community Spotlight

We are honored to recognize Markus Franz as our April 2025 Community…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 146,668 Most Valuable Professional

#2
RandyHayes Profile Picture

RandyHayes 76,287 Super User 2024 Season 1

#3
Pstork1 Profile Picture

Pstork1 66,004 Most Valuable Professional

Leaderboard
Loading complete