How-to get the unique ID of an SharePoint Online list item when creating one

For certain solutions, it is needed to know the unique ID of the SharePoint Online list item which has been created. The way to get it depends on how the item was created.

Patch
The function Patch returns a record when creating an item. When assigning this record to a collection, functions can be used to substract the ID:

ClearCollect(
        newItem,
        Patch(
            'SPList',
            Defaults('SPList'),
            {Title: "Example"}
        )
)

The ID is substracted via: First(newItem).ID

EditForm
When using an edit form, the ID is available in the property “OnSuccess” of the form control via: 'Form'.LastSubmit.ID where ‘Form’ is the name of the edit form.

Collect
This function can be used to add an item but cannot be used to get the ID. No useful/consistent data is returned from which the unique ID could be substracted.

Leave a Reply

Your email address will not be published. Required fields are marked *