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 / DataCard and UpdateCon...
Power Apps
Answered

DataCard and UpdateContext

(0) ShareShare
ReportReport
Posted on by 4

Hi,

 

Having a DataCard with data connected to a datasource etc.

How do I set a specific value to the form (or datacard) before I submit the form?

ex. if I want to set the "modified field" timestamp = now() when the press Save on a form?

 

I have tried using: UpdateContext before the submit, but that only seem to work on variables.

and have tested setting the DataCard, DataCardValue, TextBox...

 

I would like to do something like this on Button OnSelect:

DataCardTimeStamp.Text = Now();
SubmitForm(EditForm1)

 

Or if is possible to set it on the EditForm directly..

Or use UpdateContext({DataCardTimeStamp: Now()})...

But nothing seem to work..

 

Cheers

-Anders

 

 

Categories:
  • murali Profile Picture
    Microsoft Employee on at

    Wherever you are doing SubmitForm(EditForm1), you could do

     

    UpdateContext({CurrentTime: Now()});SubmitForm(EditForm1)

     

    and on the card that is supposed to contain the currenttime, you can set Default = CurrentTime.

     

    Hope this helps.

     

    Thanks

    Murali

  • Anders Carlberg Profile Picture
    4 on at

    Hi Murali,

     

    This is exactly what I have done, but it don’t seem to update the CurrentTime on Submit,

    If I remove the SubmitForm part and press the button, I dont see the field get updated.

     

    Its like UpdateContext only works on variables.

    But then I cant figure out how to connect the DataCard to a variable and get the value from the source to the variable "OnLoad".

     

    Regards

    -Anders

     

  • murali Profile Picture
    Microsoft Employee on at

    Are you setting the "Default" property of the card in question to CurrentTime?

     

    Context variables.JPG

  • Anders Carlberg Profile Picture
    4 on at

    But then I am not able to map the variable back to the form field.

     

    When Form is loaded, set the DateTime field to the field from database (as default generated app have created).

    When I press the save button, change the value (datetime) to now() and submit form.

     

    With UpdateContext I am able to update the variable, before submit

    And that means that the Datacard.Default is set to the variable CurrentTime.

    But then I am not able to show the value from the database when the form is loaded.

    As the CurrentTime variable is never mapped to the database datetime field.

    Where do put something like: UpdateContext({CurrentTime: ThisItem.ModifiedDateTime}) when the screen/form is loaded?

     

    I found a workaround, by only setting DataCard.Update = Now()

    But I rather have the field set to Now() when I Submit form.

  • Verified answer
    murali Profile Picture
    Microsoft Employee on at

    You need to use Patch then.

     

    For instance, you can do

     

    Patch(DataSource, Item_Of_Interest, Form1.Updates, {ModifiedDateTime: Now()})

     

    What this basically says is the following:

    1. Get all updates from the form

    2. Apply the modification {ModifiedDateTime: Now()} on top of Form1.Updates

    3. Edit the item of interest in DataSource

     

    https://powerapps.microsoft.com/en-us/tutorials/function-patch/

     

    Hope this helps

     

    Murali

  • murali Profile Picture
    Microsoft Employee on at

    Did the provided solution work for you?

     

    Thanks

    Murali

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    Hi,

    I'm having trouble with this.

     

    I have a SharePoint column called "Status" that is a choice type without multiselect, and I have the corresponding field in the form called "Form1". My datasource is "Contract Requests".

    I want to select a 'Submit' button to submit the form and enter a Status of "Submitted" into the Status column for the record created by this form.

     

    UpdateContext({Status:"Submitted"}) doesn't change the status column, presumably because it isn't a variable?

     

    Not sure what to enter when using Patch?

    Patch('Contract Requests', ??? , Form1.Updates, {Status: Submitted}???)

    Is the Item_OF_Interest the new record? I'm not sure how to reference the new record before the form has been submitted to create the record.

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    What would you put in for the "Item_Of_Interest" if that item is the last submitted record? Do I need to somehow associate an ID number with each record and somehow use newID: Form1_LastSubmit.ID in Form1's OnSuccess?

  • SamWallis Profile Picture
    23 on at

    Hi @Anonymous,

     

    I've been working through the same issue, and have found success in the following formula:

    Patch({SP-List-data-source}, First( Filter({SP-List-data-source}, ID = Form_RiskEdit.LastSubmit.ID)), { RiskScore: riskCalc});

    This allows you to use the auto-generated ID of the last item submitted as the Patch() record reference.

     

    Hope this helps.


    Regards,

    Sam

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 393 Super User 2026 Season 2

#2
Mohsin Ali Profile Picture

Mohsin Ali 328

#3
WarrenBelz Profile Picture

WarrenBelz 278 Most Valuable Professional

Last 30 days Overall leaderboard