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

Updating multiple propertybag values doesn't work #1218

Closed
1 task done
ronaldvanhelden opened this issue Jun 29, 2023 · 1 comment
Closed
1 task done

Updating multiple propertybag values doesn't work #1218

ronaldvanhelden opened this issue Jun 29, 2023 · 1 comment
Assignees
Labels
area: model 📐 Related to the core SDK models

Comments

@ronaldvanhelden
Copy link

Category

  • Bug

Describe the bug

When updating multiple web properties, only the first will be executed.

using this snippet, only the first gets created.

var web = await context.Web.GetAsync(x => x.AllProperties);
web.AllProperties["value1"] = "test";
web.AllProperties["value2"] = "test";
await web.AllProperties.UpdateAsync();

When I compare the request created from CSOM and PnP.Core, you can see that instead of multiple calls for SetFieldValue like CSOM there is a single call SetFieldValue with multiple parameters and that doesnt seem to work when updating multiple properties in a single update.

PNP
CSOM

And in the source in src/sdk/PnP.Core/Services/Core/CSOM/Requests/Web/UpdatePropertyBagRequest.cs, I see the following snippet for creating the request, and I think this loop should produce multiple ActionObjectPath instead of a single with multiple parameters

public List<ActionObjectPath> GetRequest(IIdProvider idProvider)
        {
            int updateActionId = idProvider.GetActionId();
            IdentityPath = idProvider.GetActionId();
            int propertiesId = idProvider.GetActionId();

            List<Parameter> parameters = new List<Parameter>();
            foreach (CSOMItemField field in FieldsToUpdate)
            {
                parameters.AddRange(field.GetRequestParameters());
            }

            return new List<ActionObjectPath>()
            {
                new ActionObjectPath()
                {
                    Action = new MethodAction()
                    {
                        Id = updateActionId,
                        Name = "SetFieldValue",
                        ObjectPathId = propertiesId.ToString(),
                        Parameters = parameters
                    },
                    ObjectPath = new Property()
                    {
                        Id = propertiesId,
                        ParentId = IdentityPath,
                        Name = PropertyName
                    }
                },
                new ActionObjectPath()
                {
                    Action = new MethodAction()
                    {
                        Id = updateActionId,
                        ObjectPathId = IdentityPath.ToString(),
                        Name = "Update",
                        Parameters = new List<Parameter>()
                    },
                    ObjectPath = new Identity()
                    {
                        Id = IdentityPath,
                        Name = $"121a659f-e03e-2000-4281-1212829d67dd|740c6a0b-85e2-48a0-a494-e0f1759d4aa7:site:{SiteId}:web:{WebId}{ObjectId}"
                    }
                }
            };
        }

Steps to reproduce

Execute this snippet

var web = await context.Web.GetAsync(x => x.AllProperties);
web.AllProperties["value1"] = "test";
web.AllProperties["value2"] = "test";
await web.AllProperties.UpdateAsync();

Expected behavior

When executing the snippet to update multiple web properties in a single call like CSOM would do.

Environment details (development & target environment)

  • SDK version: Lastest
  • OS: Windows 11
  • SDK used in: Console app
  • Framework: .Net 7
  • Tooling: LinqPad / VS
@jansenbe jansenbe added the area: model 📐 Related to the core SDK models label Jun 29, 2023
@jansenbe jansenbe self-assigned this Jun 29, 2023
@jansenbe
Copy link
Contributor

Thanks for using PnP Core SDK and reporting this @ronaldvanhelden. I've been able to reproduce and create a fix + corresponding test case for this. This change will be part of the next nightly release, as such I'm closing this issue now. If you still face issues when using the next nightly then please re-open or create a new issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: model 📐 Related to the core SDK models
Projects
None yet
Development

No branches or pull requests

2 participants