0

I have a collection (created from Sharepoint list) and I would like to overwrite the original SP list by this collection. This overwrite should be activated by an exit button after asking if I would like to exit the app.

This is the code I used in the PowerApps:

ForAll(collection; Patch(Leltár_SP_lista; Defaults(Leltár_SP_lista); { 'T$ORNO': orno; 'T$SERN': sern; 'T$CWAR': cwar;'T$LOCA':loca;'T$CPRJ': cprj; 'T$ITEM':item;'T$CNTR': cntr;'T$CLOT':clot;'T$DATE':date;'T$STUN':stun;'T$QSTK':qstk;'T$QSTR':qstr;'T$DATA':data; 'T$TIMA':tima;'T$CSTK': cstk;'T$CSTR':cstr;'T$COUN':coun;'T$PRST': prst;'T$CSTS':csts;'T$DSCA':dsca}))

The main problem is that the pressing of button (which activate this code) doesn't overwrite the Sharepoint list but merges to end of the list.

How should I modify this code to solve my problem?

jszab93
  • 5
  • 1
  • 2

2 Answers2

1

When you use Defaults() function you create a new record. If you want to overwrite the record you have to refer to the ID with a LookUp function inside the Patch as the second argument. Or you could use a ForAll function with a Remove function before patching. Please tell me if you have problems on doing this

marianr99
  • 146
  • 5
  • It works with the function RemoveIf(Sharepoint_list;true) but a little bit slow. However my list doesn't contain ID column. How can I generate automatically? – jszab93 Jul 28 '21 at 07:53
  • Every list contains an ID column, but it's hidden. If you open your list and then you go on the three dots on the right of "all items" you can click "modify this view". Then you check on the "display" column the ID. I had the same problems as yours and spent hours on discovering this.. – marianr99 Jul 28 '21 at 08:29
1

Try:

ForAll(collection; 
    Patch(
        Leltár_SP_lista; 
        LookUp(Leltár_SP_lista, ID = ThisRecord.ID); 
        {
            'T$ORNO': orno; 
            'T$SERN': sern; 
            'T$CWAR': cwar;
            'T$LOCA': loca;
            'T$CPRJ': cprj; 
            'T$ITEM': item;
            'T$CNTR': cntr;
            'T$CLOT': clot;
            'T$DATE': date;
            'T$STUN': stun;
            'T$QSTK': qstk;
            'T$QSTR': qstr;
            'T$DATA': data; 
            'T$TIMA': tima;
            'T$CSTK': cstk;
            'T$CSTR': cstr;
            'T$COUN': coun;
            'T$PRST': prst;
            'T$CSTS': csts;
            'T$DSCA': dsca
        }
    )
)
SeaDude
  • 3,725
  • 6
  • 31
  • 68