SharePoint/PnP-JS-Core

Creating Client side pages

Closed this issue · 5 comments

[ x] Enhancement

[ x] Bug

[ ] Question

Version

3.0.7

Expected / Desired Behavior / Question

When calling addClientSidePage, it should be able to add a clientsidepage no matter what the current site language is.

Observed Behavior

When calling the function on a site where english is not the main language it always fails.
I know you can specify the library title. But it should not be the goal to go and change the titles of the "Site Pages".

Error message: cannot find list with Title = x

Steps to Reproduce

Call this example in any not english site:
let web = new Web(webUrl);

    web.getList(listUrl).get().then(l => {
      console.log(l.Title);
      const page =  web.addClientSidePage(`MyFirstPage.aspx`,"dfqsdfqds",l.Title).then( (page: ClientSidePage) => {
        let test = page.listItemAllFields.get().then((fields) => {  
      });
    });
  });

Thoughts

I do not know how the page is created now. But it clearly uses getByTitle() for the list.
Wouldn't it be better to use the GetList() endpoint. That way the language does not matter.

Kind regards
Simon

Hi Simon,

Thanks for posting this!

Yes, currently, the getByTitle is used with a default value and a method of providing a custom title, which you kindly used in the sample above.

I personally also prefer web.getList as the safest and the most reasonable way of getting list instances.

I consider we'll discuss this and probably amend the thing. I'm confident with a default internal behavior changes, whereas altering arguments can provoke backward compatibility issues.

So I would propose:

  • Examine internal switch from web.lists.getByTitle to web.getList for a default library location
  • But keep the third parameter as is, as list title and still use web.lists.getByTitle for the case

Hello Koltyakov,

Ye that would be the best solution. Give the possibility to use the title for those who need it.
At the moment it is hard to retrieve the correct title when extra languages are enabled.

Thanks for the very fast response.

Kind regards
Simon

Thank you for your interest in the sp-pnp-js library. We wanted to mention that this library is being depricated in July, 2018 in favor of the new scoped pnpjs libraries. You should begin transitioning your existing projects when possible, or start new projects with the new libraries. Please see the transition guide for more details on migrating and be sure to let us know if you have any questions. Thanks!

This is now fixed with the addition of the addClientSidePageByPath method. This method has also been added to the new libraries and I encourage you to transition. Thanks!

Great thanks