cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
AGroegelich
Helper III
Helper III

Set value for on a field when submitting a form

Hi all,

 

I am trying to set a value on a field when the form is submitted.

 

In the onSelect of a button I have:

 

DataCardValue28.Text="Yes";SubmitForm(FormBewerkGebruiker)

 

Unfortunate that isn’t working. The field is not updated.

 

The idea is that this value must always be set when a user submits a form so that is why a put this code to update the field in the same button.  Is setting DataCardValue a wrong idea here? Or is there maybe a better solution, so I am open for ideas.

1 ACCEPTED SOLUTION

Accepted Solutions

Hi @AGroegelich,

Just set the Default property of that datacard (Which I believe is a textinput control) to "Yes". This way that data card will always have the value Yes and that is the value that will be submitted.

If you dont want the user to see this, you can set the visible property of the datacard to No.

Let me know if this helps.

---
If you like this reply, please give kudos. And if this solves your problem, please accept this reply as the solution.

Thanks!
Hardit Bhatia
https://thepoweraddict.com

View solution in original post

14 REPLIES 14
WarrenBelz
Super User
Super User

Hi @AGroegelich 

You are almost there

If(
   DataCardValue28.Text="Yes";
   SubmitForm(FormBewerkGebruiker)
)

 

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up

Hi Warren,

 

That only submits the form when DataCardValue28.Text="Yes". But that is not what I meant.

 

What I would like to happen is that the field in DataCardValue28is automatically updated to "Yes" when a form is submitted. The field itsself is hidden and must not be touched by the user.

The code DataCardValue28.Text="Yes" doesn't do the trick.

 

 

Hi @AGroegelich,

Just set the Default property of that datacard (Which I believe is a textinput control) to "Yes". This way that data card will always have the value Yes and that is the value that will be submitted.

If you dont want the user to see this, you can set the visible property of the datacard to No.

Let me know if this helps.

---
If you like this reply, please give kudos. And if this solves your problem, please accept this reply as the solution.

Thanks!
Hardit Bhatia
https://thepoweraddict.com

Hi @AGroegelich ,

 

Set the Default of DataCardValue28.Text to vUpdate (you can use whatever name you want for the Variable)

On the submit form do this

SubmitForm(FormBewerkGebruiker);
UpdateContext({vUpdate:"Yes"});
Reset(DataCard28)

I have used semi colons ; for new line commands (I believe you use something else ) as you use these where we use commas.

What you are doing is resetting the control when submitting, which will then take its default value, which you have set in the submit code

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

 

Hi @PowerAddict,

 

Thank you, that might work.

 

However my problem might be a bit more complex then I have told yet. I noticed the SubmitForm only save to the data source when something is changed in the form. So if the user clicks the OK button but there wasn’t changed anything (only the screen is closed).

 

So what I want to achieve is only to change the value of my field (in fact is called “Updated”) when something is modified in the form. Is that even possible?

 

But that is also the reason why I trying to update the field in the onSelect of the OK button.

Hi @WarrenBelz,

Thank you, that also works. That gives a new challange. Is somehow to to fill this Context variable with "ThisItem.Myfield" when opening the form?

Hi @AGroegelich ,

On the OnVisible property of the screen

 

UpdateContext({vUpdate:ThisItem.MyField})

 

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

Hi @WarrenBelz,

Unfortunate there is no onVisible on the EditForm in my version of PowerApps, only in the properties of the screen. Am I missing something?

Hi @AGroegelich ,

It is the screen (see post).

I made a typo and corrected it about 10 seconds later. You must have been too quick.

Helpful resources

Announcements
Power Apps News & Annoucements carousel

Power Apps News & Announcements

Keep up to date with current events and community announcements in the Power Apps community.

Community Call Conversations

Introducing the Community Calls Conversations

A great place where you can stay up to date with community calls and interact with the speakers.

Power Apps Community Blog Carousel

Power Apps Community Blog

Check out the latest Community Blog from the community!

Top Solution Authors
Top Kudoed Authors
Users online (4,415)