cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
tommyly
Level 8

Creating a blank record of a SharePoint list item while preserving the column structure

I'm working on an app where I'd like to get a blank record whose columns are based on a SharePoint list.

 

I've tried:

  ClearCollect(myCollection, First(Filter(myList, ID=-1)))

and...

  ClearCollect(myCollection, myList);

  Clear(myCollection)

 

Both of these techniques return the columns, but there technically isn't a record... it's an empty list. I want -ONE- single record that contains the columns and whose records are all nulled/blank.

 

The only other technique I can think of is:

  ClearCollect(myCollection, Filter(myList, ID=[existing ID]));

  Patch(myCollection, First(myCollection),
    {
      Column1: Blank(),
      Column2: Blank()

      ...
    }

  )

 

This seems really involved, especially since my list has over 2-3 dozen columns. Is there an easier way to do this?

 

I want to mention that my emphasis for this question is on method, not syntax (in case I messed up my syntax for whatever reason).

4 REPLIES 4
Yocomd
Level: Powered On

Re: Creating a blank record of a SharePoint list item while preserving the column structure

Do I understand correctly that you just want to add a new, empty row to your collection? I've done this using Collect:

Collect(myCollection,. {ID: Blank()})

I actually set the ID to a value, but I'm presuming Blank() will work here too)
Highlighted
Community Support Team
Community Support Team

Re: Creating a blank record of a SharePoint list item while preserving the column structure

Hi @tommyly ,

Do you want to get the Blank record from a SP List?

 

Based on the formula you provided, I think there is something wrong with it. Actually, you should not save the filtered result into a collection within your app.

Currently, within PowerApps, the collection would be acted as a Table value rather than record value. Even though, you save a Blank record into the collection, the collection would be acted as empty table rather than Blank record.

 

As an alternative solution, I think global variable could achieve your needs. You could consider save the filtered result into a variable. Please consider take a try with the following formula:

Set(BlankRecord, LookUp(myList, ID = -1))

Then you could reference the column value through the following formula:

BlankRecord.Column1
BlankRecord.Column2

...

You could review the Blank record data structure using Data Table as below:

5.JPG

 

Actually, the result the LookUp(myList, ID = -1) formula returned is just a Blank record. It is not necessary to save the the result into a collection, you could use it directly within your app.

 

If you just want to save the Blank record into a collection, and want the Blank record to be be acted as below:

6.JPG

I think the Defaults() function could achieve your needs. Please consider modify your formula as below:

ClearCollect(myCollection, Defaults(myList))

Please consider take a try with above solution, check if the issue is solved.

 

Best regards,

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
tommyly
Level 8

Re: Creating a blank record of a SharePoint list item while preserving the column structure

When I purposely filter for a non-existent ID (whether Blank() or -1), it returns an empty table--which is not my goal. My intention here is to create a real, tangible record (in contrast to a table with multiple records or a table with no records) with blank values within each field. The result would be a blank, editable record of sorts--which I'll arbitrarily call a "Blank Record" (not an empty table).

 

The ultimate goal is this: Fields on the app have their default setting dynamically set to:

  If(IsBlank(blankRecord.fieldA), copyOfDataSourceRecord.fieldA, blankRecord.fieldA)

 

When the user refreshes the data, this occurs:

  If(Connection.Connected,

    Refresh(DataSource);

    ClearCollect(copyOfDataSourceRecord, First(Filter(DataSource, ID=X)))
  )

 

That way, while offline, user input is recorded in the blankRecord collection. If the user refreshes the data, it will only refresh the fields that the user has not updated yet (because they'd be blank). The fields where the user has updated, the user's changes supersede what has updated on the data source.

 

I thought more about this and I know that you can create a sort-of-blank record using Defaults(dataSource), but I don't think this works the same way with collections--e.g. Defaults(collection)--as collections don't seem to inherit default values and meta-information of that sort.

Yocomd
Level: Powered On

Re: Creating a blank record of a SharePoint list item while preserving the column structure

Did you try the suggestion above of: 
ClearCollect(myCollection, Defaults(myList))

 

If myList is your actual data source, then presumably you'd get the defaults from there added as a new row to your collection. 

Helpful resources

Announcements
thirdimage

Power Apps Super User Class of 2020

Check it out!

thirdimage

New Badges

Check it out!

thirdimage

Power Apps Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Power Platform World Tour

Find out where you can attend!

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

SecondImage

Difinity Conference

The largest Power BI, Power Platform, and Data conference in New Zealand

Top Solution Authors
Top Kudoed Authors
Users online (5,103)