I have the following code, to Loop on all the items inside a collection named "colSItem" and patch them to a SharePoint list named @"SNMItems":-
but i want to only patch the items that are new to the collection... so how i can define to only patch the item is its id does not exists inside the collection?
Your collection should always have the same schema as the records that you wish to apply them to - or at least as close a possible.
So, if this is a collection of SharePoint records, then the ID will either have a value (existing) or be Blank() (new).
With that combination, using a formula such as this:
Path(yourDataSource, yourCollection)
will create new records and update existing records.
Note: the above formula implies and exact match to the records.
If the records do not match, then formulas like this will be equivalent:
Patch(yourDataSource,
ForAll(yourCollection,
{ID: ID,
someColumn: someCollectionColumn
}
)
)
I hope this is helpful for you.
@RandyHayessorrt i did not get your reply.. where you are checking if the item Id already exists inside the collection?
Sorry, the formula I provided would create new records and update existing.
If you are only concerned with the New items, then filter your collection by blank ID's.
And if you're creating new items only, then you can use the Collect function.
ex.
Collect(yourDataSource, Filter(yourCollection, IsBlank(ID)))
Or for the other:
Collect(yourDataSource,
ForAll(Filter(yourCollection, IsBlank(ID)),
{ID: ID,
someColumn: someCollectionColumn
}
)
)
@RandyHayes now the formula i need should work for new items + updating items.. for example when i create a new master record and i enter new child records.. on other scenarios i might edit the master record and do not add any child.. in the later approach i do not want to have duplicate items inside the child.. did you get my point?
@RandyHayes i tried your formula and still duplicate child record will be created incase i update the master record! any advice please?
Can you provide the formula you are now using as well as the formula you use to populate the collection you are using?
To Populate the collection with a new item i am using:-
and to Patch the collection to SharePoint i am using:-
Thanks
You need to change the Defaults function to specify the DataSource name - not the collection name.
@RandyHayes can you describe your point in more details? now the code to add a new Item to the collection is working well.. this code, is adding a new item to the collection without any issues
The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.
This training provides practical hands-on experience in creating Power Apps solutions in a full-day of instructor-led App creation workshop.
User | Count |
---|---|
190 | |
45 | |
43 | |
38 | |
35 |
User | Count |
---|---|
261 | |
83 | |
81 | |
70 | |
69 |