- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-03-2022 05:27 PM
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.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-03-2022 10:42 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-03-2022 09:15 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-03-2022 10:24 PM
Thanks for the reply.
I have created the following UI Macro and Client Script.
▼UI Macro
▼Client Script
However, I get the following console error.
What should I do?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-03-2022 10:42 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-03-2022 11:43 PM
Thank you very much.
It worked fine!