0

I am in one sharepoint site and want to get the news from another one

I have my method

async function fetch(sp: SPFI, filterSite: string = null) {
  try {
    const myurl = "https://mygroup.sharepoint.com/sites/my-other-site";
    const web1 = Web(myurl);
    const web2 = Web([sp.web, myurl]);
    const web3 = Web(myurl).using(SPFx(this.context));

    const web3Info = await web3();
    const web2Info = await web2();
    const web1Info = await web1();

any of these await methods throws

Error: No observers registered for this request. (https://pnp.github.io/pnpjs/queryable/queryable#no-observers-registered-for-this-request)
at Proxy.execute (queryable.js:85:1)
at Proxy.start (timeline.js:185:1)

where is the problem?

2 Answers 2

0

Below should work.

const web2 = Web([sp.web, myurl]);

Ensure the webs are imported

Import ‘@pnp/sp/webs’
3
  • it should, probably, but does not, I import { IWeb, Web } from "@pnp/sp/webs";
    – serge
    Commented Oct 21 at 10:04
  • What action you are trying to do in Web? Do you want to read the web properties or access the lists and so? I am accessing list directly like below and its working. const oWeb = Web([this.sp.web, siteURL]); const submissionItem = await oWeb.lists.getByTitle("ListName").items.select("Title", "Detail")(); Try accessing the list data after the web is initialized Commented Oct 21 at 14:29
  • solved in the posted answer
    – serge
    Commented Oct 22 at 15:44
0

what does work

import { spfi, SPFI } from "@pnp/sp";
import "@pnp/sp/fields";
import "@pnp/sp/search";
import { AssignFrom } from "@pnp/core";


const DEFAULT_SITE_URL = "https://contoso.sharepoint.com/sites/my-news-site";
export const SITE_PAGES_RELATIVE_PATH = "/SitePages";

async function fetch(sp: SPFI, filterSite: string = null) {
  try {
    const CATEGORY_FILTER = "Category eq 'Promoted'";

    const siteUrl = filterSite || DEFAULT_SITE_URL;
    const spNews = spfi(siteUrl).using(AssignFrom(sp.web));

    // Extract the relative path for the list URL
    const url = new URL(siteUrl);
    const relativePath = url.pathname + SITE_PAGES_RELATIVE_PATH;

    // Fetch the items from the "Site Pages" list
    const propoNews = await spNews.web.getList(relativePath).items
      .filter(CATEGORY_FILTER)
      .orderBy("Created", false)
      ();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.