Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default SharePoint list view does not update when adding items using Rest API #10087

Open
2 of 9 tasks
SPJS opened this issue Jan 21, 2025 · 6 comments
Open
2 of 9 tasks
Assignees
Labels
sharepoint-developer-support sharepoint-developer-support type:bug-confirmed Confirmed bug, not working as designed / expected. type:bug-suspected Suspected bug (not working as designed/expected). See “type:bug-confirmed” for confirmed bugs.

Comments

@SPJS
Copy link

SPJS commented Jan 21, 2025

Target SharePoint environment

SharePoint Online

What SharePoint development model, framework, SDK or API is this about?

💥 SharePoint Framework

Developer environment

None

What browser(s) / client(s) have you tested

  • 💥 Internet Explorer
  • 💥 Microsoft Edge
  • 💥 Google Chrome
  • 💥 FireFox
  • 💥 Safari
  • mobile (iOS/iPadOS)
  • mobile (Android)
  • not applicable
  • other (enter in the "Additional environment details" area below)

Additional environment details

Describe the bug / error

When creating a new item in a list using the default newform in a list using the latest modern UI the list automatically shows this new item. Even if I add the item in Chrome and have the same list view open in Edge, the item is immediately shown in the list view in both browsers.

If I however add a new item using REST, the list view sometimes shows the item after approximately 30 seconds for the first item - adding additional items using REST does not show the items in the view at all until I manually refresh the page or navigate to another list using the left menu and then back again.

I'm wondering how to ensure that changes made to the list is shown in the list view without having to manually reload the page.

Steps to reproduce

These steps use an example code snippet to create a new list item in a list.

  1. Create a new custom list (or use one you already have)
  2. Hit F12 to bring up the developer tools and select "Console".
  3. Type in "allow pasting" to allow pasting code
  4. Copy-paste the code snippet below in the console and hit Enter.
function createTestItem() {
  let data = {
    "formValues": [
      {
        "FieldName": "Title",
        "FieldValue": "Created with REST " + new Date().toLocaleString()
      }
    ]
  }

  try {
    fetch(
      _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getByTitle('" + _spPageContextInfo.listTitle + "')/addValidateUpdateItemUsingPath",
      {
        method: "POST",
        headers: {
          Accept: "application/json; odata=verbose",
          "Content-Type": "application/json;odata=verbose",
          "X-RequestDigest": _spPageContextInfo.formDigestValue,
        },
        body: JSON.stringify(data),
      }
    ).then(data => {
      return data.json();
    }).then(json => {
      console.log(json);
    });
  } catch (error) {
    console.log("error", error);
  }
}

createTestItem();

The output will show the list item you crated like this:

{
    "d": {
        "AddValidateUpdateItemUsingPath": {
            "__metadata": {
                "type": "Collection(SP.ListItemFormUpdateValue)"
            },
            "results": [
                {
                    "ErrorCode": 0,
                    "ErrorMessage": null,
                    "FieldName": "Title",
                    "FieldValue": "Created with REST 1/21/2025, 6:14:21 PM",
                    "HasException": false,
                    "ItemId": 0
                },
                {
                    "ErrorCode": 0,
                    "ErrorMessage": null,
                    "FieldName": "Id",
                    "FieldValue": "17",
                    "HasException": false,
                    "ItemId": 0
                }
            ]
        }
    }
}

In my command set extension I'm creating items using a custom form using something like this:
sp.web.lists.getById([GUID]).addValidateUpdateItemUsingPath(formValues);

I would appreciate some guidance on how to make the list view update to show the new items.

Expected behavior

The list view should update to show the new items within a few seconds.

Alexander

@SPJS SPJS added the type:bug-suspected Suspected bug (not working as designed/expected). See “type:bug-confirmed” for confirmed bugs. label Jan 21, 2025
@SPJS SPJS changed the title Default SharePoint list view does not updating when adding items using Rest API Default SharePoint list view does not update when adding items using Rest API Jan 21, 2025
@Tanddant
Copy link
Contributor

Possible dupe of #9342

@Ashlesha-MSFT
Copy link

Hello @SPJS,
Thank you for bringing this issue to our attention. We will look into it and get back to you shortly.

@Ashlesha-MSFT
Copy link

@SPJS,
after running code snippet in console, It is required to refresh to get item in list.

@Ashlesha-MSFT Ashlesha-MSFT self-assigned this Mar 4, 2025
@Ashlesha-MSFT Ashlesha-MSFT added the sharepoint-developer-support sharepoint-developer-support label Mar 4, 2025
@Tanddant
Copy link
Contributor

Tanddant commented Mar 6, 2025

@Ashlesha-MSFT I don't mean to come off as rude, but you can't be for real that that is your solution to this issue.

That's not taking 3 party developers seriously, it's not just when running code from the developer tools in my browser, but also from my ListView Command Set extensions, if I reload the page there the user looses all context of what's going on, if they've scrolled down a few hundred items in the list they are now thrown to the top of the page and need to scroll down again, they loose any selections they might've made, it throws them completely out of the loop.

This is something that used to work (at least partially), but with the rollout of the new-new lists design broke entirely, despite it working when just using JSON View and Column formatting, and the setvalue action.

@SPJS
Copy link
Author

SPJS commented Mar 6, 2025

@Tanddant Thanks for your comment - I just didn't feel like responding to this not at all helpful "solution"...

Alexander

@Ashlesha-MSFT
Copy link

Ashlesha-MSFT commented Mar 7, 2025

@Tanddant @SPJS,
I apologize for the inconvenience caused by the solution I provided earlier and for closing the issue prematurely. After further investigation, I was able to reproduce the issue you described. I understand that refreshing the page to get the item in the list is not an ideal solution, especially considering the impact it has on user experience, such as losing context and selections.

As We were able to reproduce the issue, and we are investigating it. We have log this as a bug, and our engineering team will look into it.
Thank you for your patience!

@VesaJuvonen VesaJuvonen added type:bug-confirmed Confirmed bug, not working as designed / expected. and removed bug labels Mar 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sharepoint-developer-support sharepoint-developer-support type:bug-confirmed Confirmed bug, not working as designed / expected. type:bug-suspected Suspected bug (not working as designed/expected). See “type:bug-confirmed” for confirmed bugs.
Projects
None yet
Development

No branches or pull requests

5 participants