locked
Save details to a table - started from scratch RRS feed

  • Question

  • Hi all, I am creating an app from scratch. I am trying to create a new entry for a table on button click. In my screen the user enters some details and those details have to be saved to my table, on clicking on the custom "save" button.

    I am trying the following formula - 

    UpdateContext({UpdatedRecord1: Patch(Emps,Defaults(Emps),EditRecord1)}); If(IsEmpty(Errors(Emps, UpdatedRecord1)), Navigate(Successful_Login, ScreenTransition.Fade, {BrowseRecord1: UpdatedRecord1}))

    We got the above formula for creating apps from data. 

    Here, Emps - is the name of my table. But this is not working. Can someone help me on how to do this for an application starting from scratch?

    Best


    Pauline Jeswin

    Wednesday, April 20, 2016 10:12 AM

Answers

  • Hi

    I can see your question from forum thru email but not here in forum. So, I write here again the complete samples with picture.

    You can either write

    RememberL your Gallery1 items is set to sample.

    1. Patch(sample, Defaults(sample), {Name: TextInput1.Text, Status: TextInput1_1.Text}) OR

    2. Patch(sample, Defaults(sample), Gallery1.Updates) provided that in Gallery1 ->CardStack -> DatCard, inside Update, you include: {Name: TextInput1.Text, Status: TextInput1_1.Text}).

    (This means, Gallery1 = {Name: TextInput1.Text, Status: TextInput1_1.Text}) )..I hope you get it.

    Important Notes

    When you see EditRecord,...those are context variable which we refer to those items we carry from another screen.

    Say: you navigate from Screen1 to Screen 2; then Navigate(Screen1, Transition, {EditRecord: Defaults(sample}).

    So, you can use EditRecord (To represent Defaults(sample)) in Screen 2 to replace Gallery1, as along as the the Gallery1 items is set to EditRecord.

    So, when you navigate from Screen1 to Screen 2, with OnSelect from your existing data (to edit), you can always write as: Navigate(Screen1, Transition, {EditRecord: ThisItem}).

    At the end, the Gallery in Screen2 items is always set to EditRecord. That means, Screen2 can be used either for: 1. New Record, or 2. Editing record. (We don't create one screen for new and one screen edit. It is redundant on very specific reason).


    PK Hong

    Thursday, April 28, 2016 1:57 AM

All replies

  • It could be that the columns that are part of EditRecord1 do not align with the Default columns of Emps.
    Wednesday, April 20, 2016 10:39 PM
  • Hi

    Patch(Emps, Defaults(Emps), EditRecord1)

    I guess something missing here: EditRecord1.Updates

    In gallery or cardstack, with reference to Table(EditRecord1), you will have several TextInput, say

    Update is entered as {Column1: TextInput1.Text, Column2: TextInput2.Text,...}

    So, when Patching, EditRecord1 must be written as EditRecord1.Updates.

    Please refer to my useful features 6: https://social.technet.microsoft.com/Forums/en-US/d38d7567-d89f-4270-8381-fa421db09db5/useful-features-of-powerapps-6?forum=PowerApHope this helps.


    PK Hong

    • Proposed as answer by PK Hong Thursday, April 21, 2016 2:02 PM
    Thursday, April 21, 2016 2:02 PM
  • Hi Hong,

    Thanks for that suggestion. I'm trying the same methods that you have shared. I've started a sample app from scratch again. Here I've taken the Card Gallery (CardStack1) and I have 2 Data cards in it for 2 text inputs. On my Save button's OnSelect property, I have written the following formula:

    Patch(sample,ThisItem,Gallery6.Updates)

    sample is my table name (I have 2 columns in it - Name and Status). 

    The Patch function is not showing an error, but the data is still not getting saved in my "sample" table. Any idea why this is happening?

    Thanks!


    Pauline Jeswin


    Wednesday, April 27, 2016 7:17 AM
  • Hi

    If you click gallery6, then Cardstack and finally DataCard, you can find Update, (On left pane). Here you must write - {Name: TextIInput1,Text, Status: TextInput2.Text}.

    This is then automatically appended within Gallery1. Updates.

    See my last reply:

                      
    0

    Hi

    Patch(Emps, Defaults(Emps), EditRecord1)

    I guess something missing here: EditRecord1.Updates

    In gallery or cardstack, with reference to Table(EditRecord1), you will have several TextInput, say

    Update is entered as {Column1: TextInput1.Text, Column2: TextInput2.Text,...}

    So, when Patching, EditRecord1 must be written as EditRecord1.Updates.

    Please refer to my useful features 6: https://social.technet.microsoft.com/Forums/en-US/d38d7567-d89f-4270-8381-fa421db09db5/useful-features-of-powerapps-6?forum=PowerApHope this helps.

    Pls check


    PK Hong


    • Edited by PK Hong Wednesday, April 27, 2016 11:34 AM add info
    Wednesday, April 27, 2016 11:33 AM
  • Hi

    I can see your question from forum thru email but not here in forum. So, I write here again the complete samples with picture.

    You can either write

    RememberL your Gallery1 items is set to sample.

    1. Patch(sample, Defaults(sample), {Name: TextInput1.Text, Status: TextInput1_1.Text}) OR

    2. Patch(sample, Defaults(sample), Gallery1.Updates) provided that in Gallery1 ->CardStack -> DatCard, inside Update, you include: {Name: TextInput1.Text, Status: TextInput1_1.Text}).

    (This means, Gallery1 = {Name: TextInput1.Text, Status: TextInput1_1.Text}) )..I hope you get it.

    Important Notes

    When you see EditRecord,...those are context variable which we refer to those items we carry from another screen.

    Say: you navigate from Screen1 to Screen 2; then Navigate(Screen1, Transition, {EditRecord: Defaults(sample}).

    So, you can use EditRecord (To represent Defaults(sample)) in Screen 2 to replace Gallery1, as along as the the Gallery1 items is set to EditRecord.

    So, when you navigate from Screen1 to Screen 2, with OnSelect from your existing data (to edit), you can always write as: Navigate(Screen1, Transition, {EditRecord: ThisItem}).

    At the end, the Gallery in Screen2 items is always set to EditRecord. That means, Screen2 can be used either for: 1. New Record, or 2. Editing record. (We don't create one screen for new and one screen edit. It is redundant on very specific reason).


    PK Hong

    Thursday, April 28, 2016 1:57 AM
  • Thank you so much Hong! This is really very clear. 

    I'm able to save values to my Sample table now. Will get back to you if I face any issues when saving values in my original application. Thank you :)

    Best Regards,


    Pauline Jeswin

    Thursday, April 28, 2016 6:11 AM
  • Hi

    Latest updates where you can learn everything - latest on 29-April2016

    https://powerapps.microsoft.com/en-us/tutorials/getting-started/


    PK Hong

    Friday, April 29, 2016 2:20 PM