Kvs.entity is undefined

Hi, I am creating a new forge app with storage for Jira Cloud. In this new app, i am trying to use the new approach kvs.entity as per the documentation.

I am getting the “entity“ is undefined error when i try to access by kvs.entity

Console error message is, “r.g.forge_fetch is not a function”.

Why i am getting this error message and how to resolve it?

Hi @rajagopal , thanks for your question!

May I ask for further details of your implementation? For example, are you trying to access kvs.entity from the @forge/kvs package from the frontend of your app?

The @forge/kvs Storage APIs cannot be accessed directly from the frontend, as they must go through the lambda. I would suggest ensuring you have defined a resolver (backend function) that accesses the kvs functionality, which can then be invoked from your frontend.

Please let me know if you have further questions. Thank you!

Hi Cherry, Thank you for your response. I am getting the below error in my terminal when i use “invoke“ in the frontend.

invocation: a8e3608e53f543c691ef57936aaa7f85 index.handler
ERROR 11:26:33.620 5122f5bc-68a5-4bfa-a026-06a500327a7d ReferenceError: window is not defined
at getCallBridge (webpack://jira-global-page-ui-kit/node_modules/@forge/bridge/out/bridge.js:9:1)
at Object.9332 (webpack://jira-global-page-ui-kit/node_modules/@forge/bridge/out/invoke/invoke.js:7:1)
at webpack_require (webpack://jira-global-page-ui-kit/webpack/bootstrap:19:1)
at Object.8350 (webpack://jira-global-page-ui-kit/node_modules/@forge/bridge/out/invoke/index.js:4:22)
at webpack_require (webpack://jira-global-page-ui-kit/webpack/bootstrap:19:1)
at Object.2321 (webpack://jira-global-page-ui-kit/node_modules/@forge/bridge/out/index.js:7:22)
at webpack_require (webpack://jira-global-page-ui-kit/webpack/bootstrap:19:1)
at C:\GC\RQGit\ilavenil\Resource-Management-Control.forge\tunnel-output\index.cjs:4343:11
at getDefinitions (webpack://jira-global-page-ui-kit/src/backend/index.js:30:49)
at Object. (webpack://jira-global-page-ui-kit/src/backend/index.js:30:49)

hi @rajagopal , would you please be able to share your app source code with us?

I have followed the steps recommended in this topic to create a new app. I am creating global page, and here is my frontend code,


import React, { useEffect, useState } from 'react';
import ForgeReconciler, { Box, Heading, Text } from '@forge/react';
import { invoke } from '@forge/bridge';
import kvs from "@forge/kvs";

const HomePage = () => {
  const [text, setText] = useState("");
  const [programs, setPrograms] = useState([]);

  const getPrograms = async () => {
    // let res = await kvs.entity("programs").query().index("program_name").getMany();
    let res = await kvs.entity("programs").get("program1")
    return res;
  }


  useEffect(() => {
    invoke('getText', { example: 'my-invoke-variable' }).then((res) => {
      setText(JSON.stringify(res));
    });
  }, []);



  return (
    <Box>
      <Box padding="20px" backgroundColor="#f4f5f7">
        <Heading size="small">Home</Heading>
        <Text>This is the home page contents.</Text>

        <Text>
          {text}
        </Text>
      </Box>
      <Box padding="20px">
        <Heading size="small">Programs</Heading>
        {programs.length > 0 ? (
          programs.map((program) => (
            <Text key={program.name}>{program.name}</Text>
          ))
        ) : (
          <Text>No programs found.</Text>
        )}
      </Box>
    </Box>
  );
}
export default HomePage;

I believe this is part of the frontend code.

The kvs import should not be happening in src/frontend/* instead only in src/resolvers/* (regarding the structure defined in the tutorial).

To invoke functions in the src/resolvers/* from the frontend the invoke should be used like in invoke(‘getText’.

1 Like

OK. How do we access the “requestJira“ and “invoke” together? It’s throwing the “window is not defined” error.

Can we use “requestJira” in the resolvers?

requestJira is available from the frontend via the bridge and is also available from the resolvers via the @forge/api package. That also has a requestJira function.