Skip to content

How do I get linked entry values? The loader.load() function must be called with a value, but got: undefined. #2044

Open
@eloisetaylor5693

Description

@eloisetaylor5693

Context

For a content model we have, there's multiple reference fields I'm looking to use to derive another field's value.

The referenced fields all have a slug field, so want to set another field to ${fieldA.slug}/${fieldB.slug}.

All referenced entries are in the same space as where we're using the app, and editing the entry.

Issue

I can't retrieve an entry by ID using the content-management package or the sdk cma in @contentful/react-apps-toolkit. On finding an entry, I get the error The loader.load() function must be called with a value, but got: undefined.

Code

import { useSDK } from "@contentful/react-apps-toolkit";
import { createClient } from "contentful-management";
...

    const sdk = useSDK<SidebarAppSDK>();

    const cma = createClient(
      { apiAdapter: sdk.cmaAdapter },
      {
        type: "plain",
        defaults: {
          environmentId: sdk.ids.environmentAlias ?? sdk.ids.environment,
          spaceId: sdk.ids.space,
        },
      }
    );

    const subjectId = subjectValue?.sys?.id;
    const subjectEntry = await cma.entry.get(subjectId);

errors with: The loader.load() function must be called with a value, but got: undefined.

I also tried:

import { useSDK } from "@contentful/react-apps-toolkit";


 const sdk = useSDK<SidebarAppSDK>();

const subjectId = subjectValue?.sys?.id;
const subjectEntry = await sdk.cma.entry.get(subjectId);
const subject = subjectEntry?.fields?.slug;

which also errors with: The loader.load() function must be called with a value, but got: undefined.

When logging the IDs, they are set. When wrapping the call to get entries with an if statement to check if the IDs are set before calling, there's the same error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions