The CreatorCon Call for Content is officially open! Get started here.

Calling UI Macro from Client Script

miyu
Tera Guru

How can I call UI macros from client scripts?
When I call UI Macro, I get a console error.
I want to call it from a client script, not a catalog client script.

1 ACCEPTED SOLUTION

Hi @miyu ,

 

It won't work that way. Reason for your error is you are calling a function setDesc() from your client script which is not defined in it, rather it's in UI Macro which is not callable from there.

 

Copy paste your script from client script and paste it inside <script> </script> section of your ui macro inside a function and call it as shown below:

 

<script>
function setValuesOnLoad(){
//Copy your client script here from line number 2 - 17

}

//Keep your previous code available in UI Macro i.e. setDesc() funstion as it is here


window.onload = setValuesOnLoad; // add this line just before </script>
</script>

 

I hope this help.

 

Please mark this helpful if this helps and Accept the solution if this solves your issue.

 

Regards,

Kamlesh

View solution in original post

8 REPLIES 8

Shubham Kumbhar
Kilo Guru

Hello @miyu ,

 

Please provide some details with screenshots so that we can help you.

 

Thank You

Thanks for the reply.
I have created the following UI Macro and Client Script.

▼UI Macro

macro.png

 

▼Client Script

client script.png

However, I get the following console error.

error.png


What should I do?

Hi @miyu ,

 

It won't work that way. Reason for your error is you are calling a function setDesc() from your client script which is not defined in it, rather it's in UI Macro which is not callable from there.

 

Copy paste your script from client script and paste it inside <script> </script> section of your ui macro inside a function and call it as shown below:

 

<script>
function setValuesOnLoad(){
//Copy your client script here from line number 2 - 17

}

//Keep your previous code available in UI Macro i.e. setDesc() funstion as it is here


window.onload = setValuesOnLoad; // add this line just before </script>
</script>

 

I hope this help.

 

Please mark this helpful if this helps and Accept the solution if this solves your issue.

 

Regards,

Kamlesh

Thank you very much.
It worked fine!