Sp-dev-fx-webparts: When using the Content by Query Webpart to get Pages on a modern communications site, _AuthorByline is not populated

Created on 10 Aug 2020  路  10Comments  路  Source: pnp/sp-dev-fx-webparts

Sample (which sample are you having trouble with)

react-content-query-webpart (online)

Authors

@PopWarner @hugoabernier @PaoloPia @spplante

Expected or Desired Behavior

Point the CQWP at a pages library so that it returns some pages. Add "_AuthorByline" to "View Fields". I would expect the author of the page to be rendered in the webpart

Observed Behavior

The field returns an "undefined" value.

Steps to Reproduce

  • Build, bundle and package the code with the --ship flag
  • Upload and deploy the SPPKG to the site collection app catalogue on a modern communications site
  • Add the CQWP to the homepage of the site
  • Point it at the Site Pages library
  • Add "Title" and "_AuthorByline" to View Field. Allow the webpart to add the default template HTML {{_AuthorByline.textValue}}
  • Publish the page - Title is populated but _AuthorByline is left null
  • Add {{log items}} to the template and republish
  • The htmlValue, rawValue, textValue properties of the _AuthorByline object are all undefined.

Environment Details (Development & Target environment)

  • OS: MacOS 10.15.5
  • Target Environment: SharePoint Online
  • Framework: Node 10.21.0
  • Browser(s): Chrome 84.0.4147.105
  • Tooling: VS Code , SPFx v1.10.0
  • Additional details: The sppkg is deployed to a site collection app catalogue, rather than farm wide. The site is a communications site in a hub.

Additional context

Needs bug

All 10 comments

Thank you for reporting this issue. We will be triaging your incoming issue as soon as possible.

@CoolrAnthony this is by design, the CQWP returns what the out-of-the-box CAML query returns, and in this case the CAML query doesn't return anything in AuthorByLine because this field is not used in modern pages, this is a classic SharePoint 2013 feature and isn't used in SharePoint Online.

SharePoint Online uses the Created By (Author) field so use this field in your CQWP and you won't have any problem 馃憤

@CoolrAnthony this is by design, the CQWP returns what the out-of-the-box CAML query returns, and in this case the CAML query doesn't return anything in AuthorByLine because this field is not used in modern pages, this is a classic SharePoint 2013 feature and isn't used in SharePoint Online.

SharePoint Online uses the Created By (Author) field so use this field in your CQWP and you won't have any problem 馃憤

I was starting to think that too, but I'm able to access the value via powershell (here's a screenshot https://ibb.co/bXf2BGh )

For clarity, the field I'm trying to return is the page author which appears in the header (in the top left corner just below the title) on a modern communications page.

After a bit more digging I've found that the AuthorByline is returned as the ID of the user in the site collection ("11" in the example in this screenshot https://ibb.co/X4P7m1L ), rather than the object which I see in Powershell.

FYI this is the generated CAML

{"query":{"__metadata":{"type":"SP.CamlQuery"},"ViewXml":"<View><Query></Query><ViewFields><FieldRef Name='Title' /><FieldRef Name='_AuthorByline' /></ViewFields></View>"}}

Yeah I just reproduced the CAML query using ajax and the response from SharePoint does not return the _AuthorByline field, instead for some reason it returns OData__AuthorBylineId and _AuthorBylineStringId so it looks like they are doing a special treatment for this field.

Any reason why you want _AuthorByline instead of Created By (author)?

I think we just found the same response at the same time ( https://ibb.co/WGVM65n ). Is there anyway to expose the OData__x005f_AuthorByline property in the Handlebars template?

I've been away from SharePoint for a few years so I'm happy for you to tell me that I'm going about this the wrong way.

I have a client who is using the Highlighted Content webpart to show a news archive. The problem is that that webpart displays the name of the most recent editor, who is usually a member of the Internal Comms team. Each news article is attributed to a senior member of the business (using the Author Byline field) and so they want that field exposing.

The HCWP doesn't have much in the way of configuration so I'm trying to recreate the archive using the CQWP.

We would have to add specific exception code for this particular field, since right now the available view fields are basically coming from web.Fields, so we list the web fields dynamically and we look for their value dynamically in the CAML query's response.

To handle this specific case the field could be hardcoded in the code on top of the dynamic logic, it's just not really elegant haha but it is possible. Did you consider the search results WebPart? It works with Handlebars just like this WebPart but has became even more powerfull with more contributors on the project.

I'll try it out tomorrow. My first go resulted in build errors.

It's sunny outside and the kids will be home soon so that's my productive hours all used up 馃憤

Thanks for looking into this @spplante

Hi @CoolrAnthony, we wanted to follow up and see if you were able to test the search results web part with any success?

Hi @CoolrAnthony, we wanted to follow up and see if you were able to test the search results web part with any success?

Hi David. Thanks for taking the time to check in.

Yes, I got it working using the search webparts. It's currently sat in the RFC queue to go to production.

I'll be honest, I found the documentation challenging, but I got there in the end.

Was this page helpful?
0 / 5 - 0 ratings