Need assistance to update the sample function with REST API function to get SP lists in to the dropdown

42 Views Asked by At

Actually we are trying to work Cascade the SharePoint list items in to dropdown, we followed a sample function from MS article , everything is fine, but now we actually want to load SP lists in to that dropdown means we need to update the SP REST API function.

Please find the sample function

private loadLists(): Promise<IPropertyPaneDropdownOption[]> {
    return new Promise<IPropertyPaneDropdownOption[]>((resolve: (options: IPropertyPaneDropdownOption[]) => void, reject: (error: any) => void) => {
      setTimeout((): void => {
        resolve([{
          key: 'sharedDocuments',
          text: 'Shared Documents'
        },
        {
          key: 'myDocuments',
          text: 'My Documents'
        }]);
      }, 2000);
    });
  }

this sample function needs to update with SP function we can see it in below.

private async _getSiteLists(): Promise<string[]>{
    const endpoint :string = `${this.context.pageContext.web.absoluteUrl}/_api/web/lists?$select=Title&$filter=(Hidden eq false)&$orderby=Title`;
    const rawResponce: SPHttpClientResponse=await this.context.spHttpClient.get(endpoint, SPHttpClient.configurations.v1);
    return(await rawResponce.json()).value.map(
      (list:{Title:string})=>{
        return list.Title;
      }
    );
  }

I don`t see any error in the code but I see webpart output returns blank in the webpart dropdown. please see the below screen show.

enter image description here

Here is the calling function which returns undefined in console log

protected async onPropertyPaneConfigurationStart(): Promise<void> {
    this.listsDropdownDisabled = !this.lists;
    console.log("From 1 st line ",this.listsDropdownDisabled); 
    //Diable the item selector untill lists have been loaded
    //Diable the item selector untill the items have been loaded or if the list has not been selected.7
    this.itemsDropdownDisabled = !this.properties.listName || !this.items;
// nothing to do untill someone has to select a list , the below condition returns true
    if (this.lists) {
      console.log("From empty line ",this.lists.toString()); 
      return;
    }

    this.loadingIndicator =true;
    this.context.propertyPane.refresh();

    //this.context.statusRenderer.displayLoadingIndicator(this.domElement, 'options');
    
    //load lists from sharepoint 
    const listOptions : IPropertyPaneDropdownOption[] = await this.loadLists();
    console.log("From 3 line ",listOptions); //**here it returns Undefined**
    this.lists=listOptions;
    this.listsDropdownDisabled=false;

    const itemsOptions: IPropertyPaneDropdownOption[] = await this.loadItems();
    this.items=itemsOptions;
    this.itemsDropdownDisabled = !this.properties.listName;

    this.loadingIndicator=false;
    this.context.propertyPane.refresh();

    
  }

Any assistance please?

your reply is really appreciated

0

There are 0 best solutions below