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 / Reset Global Variable ...
Power Apps
Unanswered

Reset Global Variable to Blank() every time PowerApps opens an item

(0) ShareShare
ReportReport
Posted on by 33

My goal is:

  • When a new item is created, the Report Submitted Date text field is blank. But today's date is entered when the Report Submitted combo box is flipped to Yes (and blanked when No or no selection is made).
  • When an existing item is viewed or edited, the Report Submitted Date is set to the existing value. But today's date is entered when the Report Submitted combo box is flipped to Yes (and the existing value is shown when No or no selection is made).

However when I open an existing item, the date is updated to Today (sometimes it is OK when I view the first item, but not subsequent items). I want it to be initially set to the existing date value. I tried setting the global variable ReportSubmittedDate to Blank() on OnHidden, OnVisible, OnNew, OnEdit, OnView...but the same behavior persists.

 

Untitled.png

 

For the Report Submitted combo box, OnChange is set to:

 

 

If(
 Self.Selected.Value = "Yes",
 Set(
 ReportSubmittedDate,
 Today()
 ),
 Set(
 ReportSubmittedDate,
 Blank()
 );
 
);

 

 

For Report Submitted text box, DefaultDate is set to:

 

 

Coalesce(
 ReportSubmittedDate,
 Parent.Default
)

 

 

 

Categories:
  • Ami K Profile Picture
    15,689 Super User 2024 Season 1 on at

    @marmot777 -

     

    Assuming you're using an Edit Form control and your data source is SharePoint, is there really a need to use a variable here?

     

    For example, if I assume that the Label control has been embedded into the DataCard for the Report Submitted Date field, apply the below to the Text property of the Label:

     

    If(
     Form1.Mode = FormMode.New && Dropdown1.Selected.Value = "Yes",
     Today(),
     If(
     Form1.Mode <> FormMode.New && Dropdown1.Selected.Value = "Yes",
     Today(),
     ThisItem.'Report Submitted'
     )
    )
  • marmot777 Profile Picture
    33 on at

    Hi Amik thank you for your help! Your solution does work for a new form. But when editing an existing record, the existing date is always shown when the "Report Submitted" combo box shows "Yes".

    I would like the "Report Submitted date" to initially show the existing date, but then update to show today's date if "Report Submitted" combo box is subsequently flipped to "Yes".

  • Ami K Profile Picture
    15,689 Super User 2024 Season 1 on at

    @marmot777 -

     

    As I understand it, you have a Dropdown control embedded into the DataCard. The Items property of that Dropdown is probably:

     

    ["Yes","No"]

     

    And the Default property is set to:

     

    "No"

     

    The code I provided performs the following:

     

    When the Form is New Mode:

    • The Date Picker defaults to blank
    • If "Yes" is selected from the Dropdown control, the Date Picker should display today's date

     

    When the Form is in Edit Mode:

     

    • The Date Picker displays the existing saved date in your data source
    • When "Yes" is selected from the Dropdown control, the Date Picker displays today's date
    • If No is selected, the Date picker should default back to the existing saved date

     

    The code provided can be applied to both the Date Picker control and the Label control. But for whatever reason it is not working for you.

     

    Could you confirm if my understanding on what you're trying to do is correct?

  • marmot777 Profile Picture
    33 on at

    The combo box options were defined in the SharePoint list originally, and the datacard is linked to that column. But you are correct in saying the options are just "No" and "Yes". Technically the Items property is set to something like:

    Choices([@'MySharePointList'].'Report Submitted')

     

    The Default property is not defined since it is a combo box, but the DefaultSelectedItems is set to Blank() unless the previous combo box (not shown in my screenshot) is set to "Yes". If the previous combo box is set to "Yes" then the default value is Parent.Default.

     

    So what I am trying to do is have the date initially show the existing record (Parent.Default) no matter if Report Submitted is "Yes" or "No". But if the Report Submitted combo box is subsequently flipped to "Yes", update the date to Today().

     

    I hope that makes sense. Thank you so much for looking at this, I really appreciate it.

  • Ami K Profile Picture
    15,689 Super User 2024 Season 1 on at

    @marmot777 - I was not aware you actually had a field called "Report Submitted" in your list and had added it as a DataCard. Irrespective of this, the code above will still behave as I described above.

     

    I do not understand why you have set the DefaultSelectedItems property to Blank, and I do not know what "previous combo box means".

     

    Either there is something about your requirement which you have not clarified, or I am just not getting it.

     

    I would suggest raising a new post with the same question and provide a link to this thread. Hopefully someone else will be able to understand this better.

     

    example.gif

     

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

Congratulations to the July Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 402 Super User 2026 Season 2

#2
Mohsin Ali Profile Picture

Mohsin Ali 328

#3
WarrenBelz Profile Picture

WarrenBelz 296 Most Valuable Professional

Last 30 days Overall leaderboard