TransWikia.com

Not able to fetch data from particular list item of site content using React APP WEB-part

SharePoint Asked by sunil b on November 30, 2021

I am able to fetch the list which we see on the landing screen of the site-content. However, when I am trying to fetch data by finding a particular item by its title I get an error CANNOT FIND LIST ‘EmployeeList’ IN THE URL.

enter image description here

I have built a React Web-part and here are the files and code

ListOfSprintStories.tsx

private _getListData(): Promise<ISPLists> {  
    return this.props.context.spHttpClient.get(this.props.context.pageContext.web.absoluteUrl + `/_api/web/lists/GetByTitle('EmployeeList')/Items`, SPHttpClient.configurations.v1)  
        .then((response: SPHttpClientResponse) => {   
          return response.json();  
        });  
    }

  private _renderListAsync(): void {
    // Local environment
    if (Environment.type === EnvironmentType.Local) {
      this._getMockListData().then((response) => {
        this.setState({ finalList: response.value });
      });
    }
    else if (Environment.type == EnvironmentType.SharePoint ||
      Environment.type == EnvironmentType.ClassicSharePoint) {
      this._getListData()
        .then((response) => {
          console.log('======>', response.value)
          this.setState({ finalList: response.value });
        });
    }
  }

  componentDidMount() {
    this._renderListAsync()
  }

IListOfSprintStoriesProps.ts

import { WebPartContext } from '@microsoft/sp-webpart-base';

export interface IListOfSprintStoriesProps {
  description: string;
  context: WebPartContext;
}

ListOfSprintStoriesWebPart.ts

import * as React from 'react';
import * as ReactDom from 'react-dom';
import { Version } from '@microsoft/sp-core-library';
import {
  IPropertyPaneConfiguration,
  PropertyPaneTextField
} from '@microsoft/sp-property-pane';
import { BaseClientSideWebPart } from '@microsoft/sp-webpart-base';

import * as strings from 'ListOfSprintStoriesWebPartStrings';
import ListOfSprintStories from './components/ListOfSprintStories';
import { IListOfSprintStoriesProps } from './components/IListOfSprintStoriesProps';
import { WebPartContext } from '@microsoft/sp-webpart-base';

export interface IListOfSprintStoriesWebPartProps {
  description: string;
  context: WebPartContext;
}

export default class ListOfSprintStoriesWebPart extends BaseClientSideWebPart<IListOfSprintStoriesWebPartProps> {

  public render(): void {
    const element: React.ReactElement<IListOfSprintStoriesProps> = React.createElement(
      ListOfSprintStories,
      {
        description: this.properties.description,
        context: this.context
      }
    );

    ReactDom.render(element, this.domElement);
  }

  protected onDispose(): void {
    ReactDom.unmountComponentAtNode(this.domElement);
  }

  protected get dataVersion(): Version {
    return Version.parse('1.0');
  }

  protected getPropertyPaneConfiguration(): IPropertyPaneConfiguration {
    return {
      pages: [
        {
          header: {
            description: strings.PropertyPaneDescription
          },
          groups: [
            {
              groupName: strings.BasicGroupName,
              groupFields: [
                PropertyPaneTextField('description', {
                  label: strings.DescriptionFieldLabel
                })
              ]
            }
          ]
        }
      ]
    };
  }
}

I have followed the documentation.

https://docs.microsoft.com/en-us/sharepoint/dev/spfx/web-parts/get-started/connect-to-sharepoint

I was able to fetch the complete site content list(Document library), but when I am trying to fetch a particular list using getByTitle(‘EmployeeList’), it fails.

Here is the error message:



{"error":{"code":"-1, System.ArgumentException","message":"List 'EmployeeList' does not exist at site with URL 'https://myTenant.sharepoint.com'."}}


Please Advice.

One Answer

Issue fixed: The WebPart was working fine locally by fetching data from _getMockListData.

However, it wasn't when I was trying to test the WebPart on the https://MyOffice365.sharepoint.com/sites/**InCorrectSPSite**/_layouts/15/workbench.aspx

I later noticed that I was pointing to wrong SP-site.

Answered by sunil b on November 30, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP