Use Api in JS | Community
Skip to main content
New Participant
February 22, 2021
Solved

Use Api in JS

  • February 22, 2021
  • 3 replies
  • 2988 views

I have create a custom js file in a clientlib with category dam.gui.coral.metadataeditor. I have added the below code to my JS:

"use strict";

use(function () {
var path = currentPage.path;
});

When I open the Properties page for my asset this JS loads. But I am seeing a console error:

Uncaught ReferenceError: Use is not defined at <myjsfile.js:2>

I am not able to use the Use Api in my javascript

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Anudeep_Garnepudi

@shaheena_sheikh 

currentPage is a server side object which can be only used in HTL JavaScript Use-API, Rhino JavaScript engine will convert JavaScript and only understands HTL global objects. You can not use HTL global object in custom Client Library JavaScript.

3 replies

Anudeep_Garnepudi
Anudeep_GarnepudiAccepted solution
New Participant
February 22, 2021

@shaheena_sheikh 

currentPage is a server side object which can be only used in HTL JavaScript Use-API, Rhino JavaScript engine will convert JavaScript and only understands HTL global objects. You can not use HTL global object in custom Client Library JavaScript.

kautuk_sahni
Employee
February 23, 2021
Thank you for sharing the answer with community.
Kautuk Sahni
raj_mandalapu
New Participant
February 22, 2021

The js use API execute at the server-side and we use this in components business logic, but I never tried this by adding category dam.gui.coral.metadataeditor,  and in this case, based on my understanding you are calling use API in metadata validation, I think this will not work. you need to use JS to get the page path and other business logic.

This is my understanding let's hear from other community members 

New Participant
February 22, 2021
i think what you are saying makes sense. That may be the issue. All I want to accomplish is to fetch currentNode property-value in my valdation and so i thought to use the USE API. Is there anyway to get that done?
raj_mandalapu
New Participant
February 22, 2021

Did you try restarting this instance? I see other people are facing this issue. check below link

https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/javascript-use-api-error-jdk-nashorn-internal-runtime/qaq-p/352704

New Participant
February 22, 2021
I saw that ticket but i dont think that's relevant because i just started my local instance but i still see the same issue