I've been attempting to retrieve lists from a SharePoint site using the provided code, however, the list isn't appearing in the response. Could someone please offer assistance with this issue? I have tried various other solutions, but the problem seems to be specifically related to fetching the list. I have double-checked that the table name and URL of the site are correctly specified in serve.json
import { IPropertyPaneConfiguration } from '@microsoft/sp-property-pane';
import { BaseAdaptiveCardExtension } from '@microsoft/sp-adaptive-card-extension-base';
import { CardView } from './cardView/CardView';
import { QuickView } from './quickView/QuickView';
import { HelloWorldPropertyPane } from './HelloWorldPropertyPane';
import { SPHttpClient, SPHttpClientResponse } from '@microsoft/sp-http';
export interface IHelloWorldAdaptiveCardExtensionProps {
title: string;
description: string;
iconproperty: string;
targetlist: string;
}
export interface IHelloWorldAdaptiveCardExtensionState {
description: string;
items:IListItem[];
}
export interface IListItem{
EmployeeName:string;
City:string;
ContactNumber:string;
BaseLocation:string;
}
const CARD_VIEW_REGISTRY_ID: string = 'HelloWorld_CARD_VIEW';
export const QUICK_VIEW_REGISTRY_ID: string = 'HelloWorld_QUICK_VIEW';
export default class HelloWorldAdaptiveCardExtension extends BaseAdaptiveCardExtension<
IHelloWorldAdaptiveCardExtensionProps,
IHelloWorldAdaptiveCardExtensionState
> {
private _deferredPropertyPane: HelloWorldPropertyPane | undefined;
public onInit(): Promise<void> {
this.state = {
description:this.properties.description,
items:[]
};
this.cardNavigator.register(CARD_VIEW_REGISTRY_ID, () => new CardView());
this.quickViewNavigator.register(QUICK_VIEW_REGISTRY_ID, () => new QuickView());
setTimeout(this.loadSpoData,500);
return Promise.resolve();
}
public get title():string{
return this.properties.title;
}
private loadSpoData=async(): Promise<void>=>{
if(this.properties.targetlist){
this.context.spHttpClient.get(
`${this.context.pageContext.web.absoluteUrl}/_api/lists/GetByTitle('MyCompanyEmployeeList')/items`,
SPHttpClient.configurations.v1)
.then((response:SPHttpClientResponse)=>{
response.json().then((responseJSON:any)=>{
const items:IListItem[]=(<any[]>(responseJSON.value))
.map<IListItem>((v:{EmployeeName:string;City:string;ContactNumber:string;BaseLocation:string;}): IListItem=>{
return{
EmployeeName:v.EmployeeName,
City: v.City,
ContactNumber: v.ContactNumber,
BaseLocation: v.BaseLocation
};
});
this.setState({
items:items
});
});
});
}
}
protected loadPropertyPaneResources(): Promise<void> {
return import(
/* webpackChunkName: 'HelloWorld-property-pane'*/
'./HelloWorldPropertyPane'
)
.then(
(component) => {
this._deferredPropertyPane = new component.HelloWorldPropertyPane();
}
);
}
protected renderCard(): string | undefined {
return CARD_VIEW_REGISTRY_ID;
}
protected getPropertyPaneConfiguration(): IPropertyPaneConfiguration {
return this._deferredPropertyPane?.getPropertyPaneConfiguration();
}
}