- 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 07:44 PM
Hello,
You can call the macro function from CS.
Macro:
<script>
function a()
{}
</script>
Client script:
You have to call that a function from Client script
a();
Also you can follow the method mentioned in the below article:-
https://www.basicoservicenowlearning.in/2020/08/call-ui-script-from-client-script.html
Please mark my answer as correct based on Impact.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-03-2022 10:30 PM
Thanks for the reply.
I have tried the above method but I get the following console error
Do I need to create a UI Script?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-03-2022 08:48 PM
Hi @miyu ,
Could you please elaborate what do you mean by calling UI macro in client script? What is in your UI Macro that you want to call? A screenshot will be more helpful to understand your issue, if you can provide.
Regards,
Kamlesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-03-2022 10:21 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?