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

SOLVED

Use Api in JS

Shaheena_Sheikh
Level 4
Level 4

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

1 Accepted Solution
Anudeep_Garnepudi
Correct answer by
Community Advisor
Community Advisor

@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.

View solution in original post

7 Replies
Shaheena_Sheikh
Level 4
Level 4
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
raj_mandalapu
Community Advisor
Community Advisor

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 

Shaheena_Sheikh
Level 4
Level 4
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?
Anudeep_Garnepudi
Correct answer by
Community Advisor
Community Advisor

@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.

View solution in original post

kautuk_sahni
Community Manager
Community Manager
Thank you for sharing the answer with community.