2

I am creating a form where end user can submit their form entries by clicking Submit button. The Datasource for this task is Excel table. I created 2 screens.[SEE BELOW FOR MORE UPDATE]

Screen1 contains Summary of many systems (Sys1,Sys2,Sys3...) in the Gallery form. When End user clicks on one of the tab (Say "Sys1"), it takes them to new screen(which contains Sys1 detail information) where end user can Signup, by looking at the summary screen. I added "Signup" button at the bottom of the screen, which navigates to Screen 2.

Screen 2 contains edit form where end user can signup for System. I also wanted to use some values from Screen 1 (Say System 1 ID,Model# etc). So for those items, I set their "Item" property to Gallery.Selected, and disabled those fields so end user cannot edit those fields. Fields that needs end user's input are in "Text box" form such as "Signup by", "Signup Time" etc. I have submit button at the bottom of the screen. So end user can submit the form. The "OnSelect" property of Submit button is set to SubmitForm(Form1).

I have two issue with above process

  1. When user clicks Submit button, Previous entry in Excel table is getting overwritten. I would like to save previous entries as well
  2. When Screen2 is re-open all the previous entries are not getting clear

Update after Arun's comment

The code suggested by Arun for Create and Update is not something I am looking for. The create code Appends two new row in Excel table. The Update code removes the last assigned value. I am looking for a way in Powerapps , Where PowerApps code will first find the row in below case "Sys1" and Update that row as "User1" and "Mod1" for the column. Let's say "User1" wants to add another model for "Sys1" row, it will append at the bottom of the Excel table, as shown in Figure 2. Figure 2 is my desired output. Figure 1 is my initial Excel table.

Figure 1 Initial Excel Table (Data Source)

enter image description here

Figure 2: Expected Output

enter image description here

biggboss2019
  • 220
  • 3
  • 8
  • 30
  • so what you need is "if, else" block, if there is an entry already - Patch update, else Patch create as in my answer :) – Arun Vinoth-Precog Tech - MVP Oct 02 '20 at 19:14
  • @ArunVinoth..I was thinking of same, but wasn't sure how to write it ?If possible could you help on that ?Thanks in advance! :) – biggboss2019 Oct 02 '20 at 19:20
  • updated my answer, I have not tested it. pls verify – Arun Vinoth-Precog Tech - MVP Oct 02 '20 at 19:35
  • @ArunVinoth Thanks for updating the answer. Everytime I run Edited code, Only Else condition gets executed ("Create" Code). Not sure what's the issue ? – biggboss2019 Oct 05 '20 at 17:03
  • that simply means if condition is not satisfying. Can you verify the condition why it’s not matching and hard code it to troubleshoot if needed. – Arun Vinoth-Precog Tech - MVP Oct 05 '20 at 17:06
  • @ArunVinoth..I think I found a flaw in the Edited code. I excluded Model= " " from code,because this condition is always going to be TRUE.Since I have pre-populated System number in System text box, everytime code is run there is always going to 1 row present (ex:"Sys1"). Since 1>0. Edited Code only runs TRUE condition., Which is your suggested Update code. I was wondering if there a way where after first entry we can do lookup agian and check if there is already present for that system ? If it is present then append new row else update the existing row. I am not sure how to achieve this ? – biggboss2019 Oct 07 '20 at 14:38
  • thats essentially what you want, if Model is empty and System1 entry is there - then you have to update it. Else create a new entry - correct? – Arun Vinoth-Precog Tech - MVP Oct 07 '20 at 14:44
  • correct!However, I am not sure why EDITED code is not working ? Does it have to do with Default property of my Textboxes ? The Default Property for System is set to Gallery2.Selected.System and the Defauly property for Model is set to " ". Am I missing anything ? – biggboss2019 Oct 07 '20 at 14:49
  • my bad, I have updated again, sorry. I dont have access to apps right now to test it. Pls read this and amend the code for testing - https://powerusers.microsoft.com/t5/Building-Power-Apps/Lookup-with-2-conditions-not-working/td-p/325253 – Arun Vinoth-Precog Tech - MVP Oct 07 '20 at 15:04
  • 1
    Unfortunately, now the edited code is running FALSE condition (Create) condition only. :( Will try to check your reference. – biggboss2019 Oct 07 '20 at 15:15

1 Answers1

1

You should use Patch to write/append to excel file instead of SubmitForm(Form1).

For create:

Patch(ExcelSource, 
Defaults(ExcelSource), 
{NameColumn: TextInput.Text, SurveyResultColumn: Value})

For update:

Patch(ExcelSource, 
LookUp(ExcelSource, NameColumn=TextInput.Text), 
{NameColumn: TextInput.Text, SurveyResultColumn: Value})

Read more

Edit:

Please replace with your control names & values, I tried my best assumption :)

If(CountRows(Filter(Table1, System=SystemControl.Text && Model=""))>0, 
    Patch(Table1,LookUp(Table1, System=SystemControl.Text && Model=""), {Model: DatacardValue10.Text, UserName: UserControl.Text}), 
    Patch(Table1,Defaults(Table1),{System:SystemControl.Text, Model: DatacardValue10.Text, UserName: UserControl.Text}))

Reference

  • Thanks for reply! I tried above code and for some reason I am getting an error which says "A field named "Pr" was specified more than once in this record". The code I tried was Patch(Table1,LookUp(Table1,Pr=DatacardValue10.Text),{Pr:DatacardValue10.Text,Pr:Datacardvalue10}). Here Pr= Column Name. Any suggestion what is wrong with my above code ? Thanks in advance! – biggboss2019 Oct 01 '20 at 12:46
  • @biggboss2019 try this: `Patch(Table1,LookUp(Table1,Pr=DatacardValue10.Text),{Pr:DatacardValue10.Text})`. You have Pr: which is assignment twice :) – Arun Vinoth-Precog Tech - MVP Oct 01 '20 at 13:50
  • Thanks! Seems like on-clicking Submit button. I cannot save my entry in my excel. The default value for DatacardValue10 is set to " ". Any suggestion ? – biggboss2019 Oct 01 '20 at 14:05
  • @biggboss2019 see my update, make sure the control names are correct and value is correct while creating record – Arun Vinoth-Precog Tech - MVP Oct 01 '20 at 14:18
  • Sorry for asking naive question. What exactly is a Value ? Since, it is DataCard with Text input. I thought the Value will be "DataCardValue10.Text"? Isn't it correct ? – biggboss2019 Oct 01 '20 at 14:36
  • 1
    @biggboss2019 yes, correct. Try hard coding some value and see first. – Arun Vinoth-Precog Tech - MVP Oct 01 '20 at 14:43
  • 1
    Also, I think my question was misunderstood.What I am looking for is first PowerApp form will find the row that has "System" row. Say "Sys1" and update that row with Model information. Next time when user again selects "Sys1" the information entered by user will be appended in new row. – biggboss2019 Oct 01 '20 at 14:44
  • Please see above Update. Thanks in advance! :) – biggboss2019 Oct 01 '20 at 20:07
  • @biggboss2019 sorted out? able to make it working ? – Arun Vinoth-Precog Tech - MVP Oct 09 '20 at 12:48
  • Not Yet still trying to figure out :( – biggboss2019 Oct 09 '20 at 12:51
  • ..Any solution for this issue -> https://stackoverflow.com/questions/64376416/powerapps-is-submitting-time-along-with-date-in-wrong-format-only-date-is-neede – biggboss2019 Oct 16 '20 at 14:37