Issue with one of the customer's Freshdek account

Hello Team,

I am using the below format in app.js

image

There is an issue with this format as in customer’s account, once the custom APP is saved by changing few fields in it, it is giving an error.

The error: “app is not defined.”

The same error is not coming in other freshdesk account.

Please let me know if I am missing something.

Regards,
Akhil S K

@Akhil_Kulkarni,
I think you need to wrap the code inside the document-ready method, once all the scripts are loaded (freshclient) and then you need to execute your code.

Thanks

Hello Santhosh,

After “fdk create”, we will get the below file structure.

If we use the document-ready method, the error will be “$ not defined”.

you can use like this

 document.onreadystatechange = () => {
      if (document.readyState === 'complete') {
        // your code
    }
}

Hope it helps

@Akhil_Kulkarni Same as @Santhosh said, you can call the global app object after DOM is ready. Here is an example: entity-storage-samples/employee.js at main · freshworks-developers/entity-storage-samples · GitHub.

@Akhil_Kulkarni The value of app becomes available to the app using

    <script async src="https://static.freshdev.io/fdk/2.0/assets/fresh_client.js"></script>

in the associated HTML file.

You must ensure that your app.js starts to execute after fresh_client.js first executes

    <script async src="https://static.freshdev.io/fdk/2.0/assets/fresh_client.js"></script>
    <link rel="stylesheet" type="text/css" href="styles/style.css" />
  </head>

  <body>
    <div class="main">
      <p>Utilize this template code to build your App</p>
      <p id="apptext"></p>
    </div>
  </body>

  <script defer src="scripts/app.js"></script>
  <script async type="module" src="https://unpkg.com/@freshworks/crayons@3/dist/crayons/crayons.esm.js"></script>
  <script async nomodule src="https://unpkg.com/@freshworks/crayons@3/dist/crayons/crayons.js"></script>
</html>

You can ensure it by understanding the difference: Scripts: async, defer

Usually, if you do not solve the order of scripts loading using async or defer, then next option is to fall back to enclosing document loading apis such as document.onreadystatechange or document.readyState etc.,

1 Like

Hello @Santhosh

I have tried the solution you have provided and is giving the below error.

Please can we get on a quick call once.