cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
fsim
Level: Powered On

fill in form fields before submitform

Hi all !

It's probably simple but I'm not able to find a way to fill in some fileds of a form that is linked to a datasource before I submit it.

In my form, I have a read only field that contains the email of the last user who modified the record. I want, just before the submit, to modify this modified_by with user().email. 

So, the datacard.default = thisitem.modified_by. At the saving time (ie in the onselect of the button) I want it to be user().email. 

same with modified_at and few others more.

 

ps) I tried to patch the thisItem, but it does not work. should I fill in the form with a collection, patch the collection and then save the collection to the datasource ? if yes, what about new records ? how can I create an empty collection with all the fields of the form ?

 

I also tried this unsuccessfully.

If( IsBlank(Created_at_DataCard5.Default),DataCardValue47.Text=Now());
If( IsBlank(Created_by_DataCard2.Default),DataCardValue3.Text=User().Email);
DataCardValue4.Text=Now();
DataCardValue5.Text=User().Email;

SubmitForm(Form1);

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Community Support Team
Community Support Team

Re: fill in form fields before submitform

Hi @fsim ,

Could you please share a bit more about the data source you used in your app? Is it a SP list?

Do you want to modify the Modified_By column with User().Email before you press the "Submit" button?

Further, could you please share a bit more about the 

 

If the data source is a SP List, I think it is not necessary to do the update operation in your app. The Modified_By column would be modified automatically by SP System when anyone modified an item record. In addition, the Modified_By column is a System column in SP list, we could not update it in PowerApps app.

 

If the data source you used in your app is not a SP List, and the Modified_By column is a Text type column (store the email address of a user), please consider take a try with the following workaround:

Set the OnSuccess property of the Edit form (Form1) to following:

 

Patch(
          'YourDataSource',
           Form1.LastSubmit,
           {
              Modified_By: User().Email
           }
)

or

Patch(
          'YourDataSource',
           LookUp('YourDataSource', 'PrimaryColumn' = Form1.LastSubmit.'PrimaryColumn'),
           {
              Modified_By: User().Email
           }
)

When you submit your Form data successfully via pressing the "Submit" button, above Patch function would be executed automaticaily to update the Modified_By column value.

 

Please consider take a try with above solution, check if the issue is solved.

 

More details about the Patch function, please check the following article:

Patch function

 

Best regards,

 

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

7 REPLIES 7
mdevaney
Level 8

Re: fill in form fields before submitform

I’d suggest you go to the Update property of your data card and change the value to User().email. The update property controls what is submitted to the datasource
Super User
Super User

Re: fill in form fields before submitform

Hi @fsim 

 

If your data source is a sharepoint list , Modified and Modified By columns (internal columns) will automatically be set to the person who last modified the item in PowerApps

 

Regards,

Reza Dorrani

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

mdevaney
Level 8

Re: fill in form fields before submitform

Yep I agree with Reza. That’s the simplest way to do it. Modified column exists already in SP. no need to create a 2nd modified field.
Community Support Team
Community Support Team

Re: fill in form fields before submitform

Hi @fsim ,

Could you please share a bit more about the data source you used in your app? Is it a SP list?

Do you want to modify the Modified_By column with User().Email before you press the "Submit" button?

Further, could you please share a bit more about the 

 

If the data source is a SP List, I think it is not necessary to do the update operation in your app. The Modified_By column would be modified automatically by SP System when anyone modified an item record. In addition, the Modified_By column is a System column in SP list, we could not update it in PowerApps app.

 

If the data source you used in your app is not a SP List, and the Modified_By column is a Text type column (store the email address of a user), please consider take a try with the following workaround:

Set the OnSuccess property of the Edit form (Form1) to following:

 

Patch(
          'YourDataSource',
           Form1.LastSubmit,
           {
              Modified_By: User().Email
           }
)

or

Patch(
          'YourDataSource',
           LookUp('YourDataSource', 'PrimaryColumn' = Form1.LastSubmit.'PrimaryColumn'),
           {
              Modified_By: User().Email
           }
)

When you submit your Form data successfully via pressing the "Submit" button, above Patch function would be executed automaticaily to update the Modified_By column value.

 

Please consider take a try with above solution, check if the issue is solved.

 

More details about the Patch function, please check the following article:

Patch function

 

Best regards,

 

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

fsim
Level: Powered On

Re: fill in form fields before submitform

@RezaDorrani , hello !

Thank you for your answer. The database is a SQL table.

fsim
Level: Powered On

Re: fill in form fields before submitform

hi @mdevaney 

I gave a try to your solution and had this issue. All the fields I want to modified are view text fields. Therefore, there is no Update property avalaible. :-/

 

fsim
Level: Powered On

Re: fill in form fields before submitform

Hello Kris ! 

thank you for your support.

Here is the way I set it, using your suggestion: 

 

Patch(
'[CIT].[ProjectHeader]',
LookUp('[CIT].[ProjectHeader]', Project_number = Form1.LastSubmit.Project_number),
{
Lastmodified_by: User().Email,
Lastmodified_at: Now()
}
);

If(IsBlank(Created_at_DataCard5.Default),
Patch(
'[CIT].[ProjectHeader]',
LookUp('[CIT].[ProjectHeader]', Project_number = Form1.LastSubmit.Project_number),
{
Created_by: User().Email,
Created_at: Now()
}));Notify("Data saved successfully", NotificationType.Success);Back();

Helpful resources

Announcements
firstImage

Microsoft Business Applications Virtual Launch Event

Join us for an in-depth look at the new innovations across Dynamics 365 and the Microsoft Power Platform.

firstImage

Watch Sessions On Demand!

Continue your learning in our online communities.

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

FirstImage

Power Platform World Tour

Coming to a city near you

thirdimage

PowerApps Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

FourthImage

Join PowerApps User Group!!

Connect, share, and learn with your peers year-round

Top Kudoed Authors
Users Online
Currently online: 404 members 4,399 guests
Please welcome our newest community members: