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

C# cannot configure SPFx webpart searchable properties via CSOM ? Package or SharePoint bug ? #451

Closed
patrickblanc opened this issue Aug 24, 2021 Discussed in #449 · 2 comments
Assignees

Comments

@patrickblanc
Copy link

patrickblanc commented Aug 24, 2021

Hello guys

I am facing the following problem with PnP.Framework package and the problem seems to be the same in SharePointPnPCoreOnline package.

Discussed in #449

Originally posted by patrickblanc August 18, 2021
I am adding a webpart like this :

var component = page.AvailablePageComponents().FirstOrDefault(c => new Guid(c.Id) == new Guid("GUID"));
if (component != null)
{
    var webpart = page.NewWebPart(component);
    AccordionProperties properties = new ()
    {
        Description = "Accordion",
        AccordionItems = items,
    };

    webpart.PropertiesJson = JsonSerializer.Serialize(properties, new JsonSerializerOptions()
    {
        PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
        WriteIndented = true,
    });
    page.AddControl(webpart, page.Sections[0].Columns[0]);
}

My custom SPFx webpart set the properties as searchable with the following configuration in the typescript webpart file :

protected get propertiesMetadata(): IWebPartPropertiesMetadata {
  return {
    'accordionItems[*].header': { isSearchablePlainText: true },
    'accordionItems[*].content': { isSearchablePlainText: true },
  }
}

My problem is the following, on the webpart, we can't set webpart.ServerProcessedContent property by code. It sounds legit as it seems to be a Server Processed Content, according to the name, but it seems not automatically updated during the process. So the webpart in the page looks like this (adding ?maintenanceMode=True at the end of the page URL) :

image

If I search the text within my webpart in the search at this moment, no result is found.

But if I click on the edit button on the modern page and save it directly (without doing any change on the webpart or the page)... then the properties is empty, but the serverProcessedContent contains my items and it is now searchable.

image

Then if I am searching for the webpart text content, result start appearing in the search.

For me it sounds ok to be able to set only PropertiesJson on the webpart object. And I have the feeling this is not a problem related with PnP.Framework but with Sharepoint itself. As described above, if we set the PropertiesJson and then add the webpart into a page, then SharePoint during the process should check the PropertiesJson and extract the searchable properties to remove those from PropertiesJson and update the ServerProcessedContent properties... or we should be able to define which properties are property only and which properties are searchable properties (html, plain text... etc) before sending the request to SharePoint.

This is a serious lack if we plan to migrate classic page into modern page because the old content should be searchable.

@patrickblanc patrickblanc changed the title C# how to configure SPFx webpart searchable properties C# cannot configure SPFx webpart searchable properties via CSOM ? Package or SharePoint bug ? Aug 24, 2021
@jansenbe jansenbe self-assigned this Aug 25, 2021
@jansenbe jansenbe reopened this Aug 25, 2021
@jansenbe
Copy link
Contributor

@patrickblanc : when you set the PropertiesJson attribute of the web part the json you provide can contain a serverProcessedContent node...you can try to configure your web part in workbench and then copy the relevant json as described here (https://pnp.github.io/pnpcore/using-the-sdk/pages-webparts.html) and shown below:
image

@patrickblanc
Copy link
Author

@jansenbe thanks for the clarification, it is working like a charm 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants