Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn More

View all

Sign in to view all badges

Use Api in JS

Avatar

Avatar
Validate 10
Level 2
Shaheena_Sheikh
Level 2

Like

1 like

Total Posts

86 posts

Correct Reply

0 solutions
Top badges earned
Validate 10
Validate 1
Give Back
Boost 1
Applaud 5
View profile

Avatar
Validate 10
Level 2
Shaheena_Sheikh
Level 2

Like

1 like

Total Posts

86 posts

Correct Reply

0 solutions
Top badges earned
Validate 10
Validate 1
Give Back
Boost 1
Applaud 5
View profile
Shaheena_Sheikh
Level 2

21-02-2021

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

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar
Establish
MVP
Anudeep_Garnepudi
MVP

Likes

271 likes

Total Posts

320 posts

Correct Reply

87 solutions
Top badges earned
Establish
Ignite 1
Give Back 5
Give Back 3
Give Back 10
View profile

Avatar
Establish
MVP
Anudeep_Garnepudi
MVP

Likes

271 likes

Total Posts

320 posts

Correct Reply

87 solutions
Top badges earned
Establish
Ignite 1
Give Back 5
Give Back 3
Give Back 10
View profile
Anudeep_Garnepudi
MVP

21-02-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.

Answers (2)

Answers (2)

Avatar

Avatar
Validate 1
MVP
raj_mandalapu
MVP

Likes

124 likes

Total Posts

203 posts

Correct Reply

72 solutions
Top badges earned
Validate 1
Contributor
Shape 1
Give Back 5
Give Back 3
View profile

Avatar
Validate 1
MVP
raj_mandalapu
MVP

Likes

124 likes

Total Posts

203 posts

Correct Reply

72 solutions
Top badges earned
Validate 1
Contributor
Shape 1
Give Back 5
Give Back 3
View profile
raj_mandalapu
MVP

21-02-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 

Avatar

Avatar
Validate 1
MVP
raj_mandalapu
MVP

Likes

124 likes

Total Posts

203 posts

Correct Reply

72 solutions
Top badges earned
Validate 1
Contributor
Shape 1
Give Back 5
Give Back 3
View profile

Avatar
Validate 1
MVP
raj_mandalapu
MVP

Likes

124 likes

Total Posts

203 posts

Correct Reply

72 solutions
Top badges earned
Validate 1
Contributor
Shape 1
Give Back 5
Give Back 3
View profile
raj_mandalapu
MVP

21-02-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-j...