web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Setting the selected d...
Power Apps
Answered

Setting the selected date as a global variable for further use.

(0) ShareShare
ReportReport
Posted on by 27

I have a form with two date pickers. I'd like to save it as a global variable after selecting a date in date picker 2. Then, after saving the form, I would like the saved date in the new form to be set as the default value for date picker 1. I tried the following codes in on change for data picker 2:

 

"Set(ChangedDose; DataCardValue50.SelectedDate)"

 

and also the following code for the default on date picker 1:

 

"ChangedDose"

 

I assigned the save record button to the following code on select:

 

"SubmitForm(Form1);;Refresh('Data1');;UpdateContext({resetdate: true});;UpdateContext({resetdate: false})"

 

Reset for both date pickers is set to local variable "resetdate".

 

Unfortunately, when selecting a date, the global variable is not saved correctly and the blank value is returned with the date type.

Categories:
  • Verified answer
    RandyHayes Profile Picture
    76,299 Super User 2024 Season 1 on at

    @Aravial 

    This is all best done in your OnSuccess action of your form.

     

    Your Formula for submitting the for should ONLY ever be: SubmitForm(Form1)

    A form submits asynchronously, so it immediate performs the functions after your submitform, even before the form has submitted. So changing the form or deriving anything from it during that phase is not guaranteed to accurate.

     

    Your OnSelect of your save record button should be:  SubmitForm(Form1)

     

    Your OnSuccess action Formula on the form should be:

        Set(ChangedDose; Self.LastSubmit.fieldNameForDatepicker);;

        UpdateContext({resetdate: true});;UpdateContext({resetdate: false})

    Note: refreshing the datasource is not needed and will only slow your app.  The data you submitted will all be in the datasource already.

     

    In the above, change the field name to the field that contains the date from DatePicker 2.

    Get rid of the OnChange formula for the datapicker.

     

    You can keep your DefaultDate on the other date picker as ChangeDose

     

    I hope this is helpful for you.

     

     

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 397 Super User 2026 Season 2

#2
Mohsin Ali Profile Picture

Mohsin Ali 354

#3
WarrenBelz Profile Picture

WarrenBelz 232 Most Valuable Professional

Last 30 days Overall leaderboard