Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
eloisetaylor5693 opened this issue Jul 10, 2024 · 0 comments

Comments

@eloisetaylor5693
Copy link

eloisetaylor5693 commented Jul 10, 2024

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.

@eloisetaylor5693 eloisetaylor5693 changed the title How do I get linked entry values? How do I get linked entry values? The loader.load() function must be called with a value, but got: undefined. Jul 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant