1

I have two search web parts. The are based on each other, that is is that they pretty much does the same thing with some lesser tweaking. The have different product ID and alias. Only the code is similar.

Problem is that I can't have both web parts working - if I put one of the web parts in one page, and the other on a different page on the same site it does not work. It does not work if I put the web part in a sub site as well. It works in online workbench.

In console I get the following error:

Uncaught (in promise) Error: Error making HttpClient request in queryable [404] ::>

The code I have for my search

 import { WebPartContext } from "@microsoft/sp-webpart-base";
 import pnp, { SearchQuery, SearchQueryBuilder, SearchResults, SearchResult 
     } 
from '@pnp/pnpjs';

export class ProjectItemProvider {
private context: WebPartContext;

constructor(context: WebPartContext) {
    this.context = context;
}

public GetSiteItemsByContentId(contentTypeId: string, selectProperties: string[]): Promise<SearchResult[]> {
    const _searchQuerySettings: SearchQuery = {
        TrimDuplicates: false,
        RowLimit: 500, 
        SelectProperties: selectProperties.concat(["ParentLink"])
    };

    let q = SearchQueryBuilder(`ContentTypeId:${contentTypeId}*`, _searchQuerySettings).rowLimit(500);
    const srPromise = new Promise<SearchResult[]>((resolve, reject) => {
        pnp.sp.search(q).then((response: SearchResults) => {

            resolve(response.PrimarySearchResults);
        });
    });
    return srPromise;
}
  }

Maybe its the context that messes it up? If so, what could I do about it?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.