cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Super User
Super User

Bug: Patching to an existing record in a collection - initially blank fields not updated

Issue:

A collection, based on a SharePoint list, is populate with new records where some fields are blank. When Patching to those new records, updating both blank and non-blank fields in the same command, the non-blank fields update as expected, but the blank fields remain blank. No error is given.

 

Scenario:

I add records to a collection (colSurveyResponses) that is based on a SharePoint list

//Create all Survey responses
    Clear(colTempSurveyResponses);
    ForAll(
        SortByColumns(
            Filter(
                colSurveyQuestions,
                QuestionActive = true
            ),
            "QuestionOrder",
            Ascending
        ),
        Collect(
            colTempSurveyResponses,
            {
                SurveyQuestion: ID,
                Title: TheSelectedSurvey,
                SurveySection: Section.Value,
                ResponseYN:-1,
                FollowUp: 0,
                ResponseComment: " "
            }
        )
    );//Now patch all the data in one hit for better performance
  Collect(colSurveyResponses,colTempSurveyResponses)

In summary: I iterate through colSurveyQuestions building up colTempSurveyQuestions row by row. I then load all of these into the collection colSurveyResponses which is based on SharePoint list and includes the field names as given above along with all the normal SharePoint fields (Modified, Created, ID, etc).

 

When colSurveyResponses is populated with new records from colTempSurveyResponse, several fields are blank. If I perform a Patch I cannot update the blank fields! In the above code, I am setting the ResponseComments field to " " as this then allows me to update the field. If I do not set an initial value and Patch several fields on the same row, including ResponseComments, then ResponseComments remains blank but the other fields *are* updated. No error is given.

    Patch(
        If(
            varBlnConnected,
            SurveyResponses,
            colSurveyResponses
        ),
        First(
            Filter(
                If(
                    varBlnConnected,
                    SurveyResponses,
                    colSurveyResponses
                ),
                Title = TheSelectedSurvey && SurveyQuestion = galSurveyQuestion
            )
        ),
        If(
            varBlnConnected,
            {
                Title: TheSelectedSurvey,
                ResponseYN: If(
                    CheckboxY.Value = true,
                    1,
                    CheckboxNo.Value = true,
                    0,
                    -1
                ),
                ResponseComment: txtComments.Text,
                FollowUp: CheckboxFU.Value
            },
            {
                Title: TheSelectedSurvey,
                ResponseYN: If(
                    CheckboxY.Value = true,
                    1,
                    CheckboxNo.Value = true,
                    0,
                    -1
                ),
                ResponseComment: txtComments.Text,
                FollowUp: CheckboxFU.Value,
                Modified: Now(),
                '{Identifier}': "Modified"
            }
        )
    

The above code, when the app is running offline (varBlnConnected = false), is simply patching an existing record in colSurveyResponses, updating the fields ResponseComment, FollowUp, Modified and Identifier. Where new records have been added to the collection the fields Modified and Identifier (and ResponseComment unless I add the =" " as in the first code block) and are empty, the fields are not updated, but Title, ResponseYN and FollowUp (which always have an initial value) do update.

6 REPLIES 6
Highlighted
Super User
Super User

I experienced this same behavior, though my collection is from Azure SQL. Using the same Patch and changing the data source I am able to write to the database as expected but not to the collection if there are blank fields. No errors shown in my case either.
Highlighted

Hi @PaulD1 and @wyotim,

 

Please try enabling Formula-level error management in Advanced settings:

126.png

 

Otherwise null/empty values are not sent on Patch requests.

 

Regards,

Michael

Community Support Team _ Michael Shao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Highlighted

Thanks @v-micsh-msft

 

I tried turning on formula level error management as suggested, but it didn't make any difference.

 

In a collection, when attempting to update (via Patch) a single record, only fields that already contain data can be modifed. Fields that are blank (null) will not accept any new value.

 

E.g. there is a record in the collection with field ABC currently has a null value - I attempt to use Patch to update the value of the field to 'Test' and nothing happens. 

E.g. there is a record in the collection with field XYZ currently has a value of 'aaa' - I attempt to use Patch to update the value of the field to 'Test' and the field is changed as expected.

 

I am currently trying to implement an offline mode for my app where collections are populated based on the current data in SharePoint lists. When the app is offline, it patches to the collections instead of to the SharePoint lists. There are many fields that are initially empty and these cannot be updated via Patch becuase of this bug.

 

The bug is easy to reproduce. Connect to a SharePoint list which has some populated and some unpopulated fields. Create a Collection of this SharePoint data. Attempt to pach to a record specifying a new value for both a populated and an unpopulated field. Only the already populated field will accept a new value.

Highlighted

@v-micsh-msftI can also confirm that this solution didn't work, unfortunately. I made sure to do the required save and reload and there was no change in behavior (i.e. it will not write to a previously blank field). Anything else we can try?

 

And just to be clear from the last sentence in your response, the issue is not trying to write a null/empty value but rather writing a non-null/non-empty value to an empty field in a collection. Thanks for the assistance!

Highlighted

Hi @PaulD1 and @wyotim,

 

Thanks for the follow ups and apologize for the late response.

The symptom could be confirmed from my side for the SharePoint list.

It seems the empty fields saved in collection, no matter which type it is, it will never work with the patch update.

Please consider switch the function to UpdateIf, and see if it works in your scenario.

 

Regards,

Michael

Community Support Team _ Michael Shao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Highlighted

@v-micsh-msft Thanks for following up! Good call on UpdateIf. I’ll give it a go tomorrow. Thanks again!

Helpful resources

Announcements
Community Conference

Power Platform Community Conference

Check out the on demand sessions that are available now!

News & Announcements

Community Blog

Stay up tp date on the latest blogs and activities in the community News & Announcements.

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Community Highlights

Community Highlights

Check out the Power Platform Community Highlights

Top Solution Authors
Top Kudoed Authors
Users online (12,427)