- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-13-2020 08:17 AM
I'm trying to call a UI Macro from an onChange Catalog client script to dynamically add help messages on order form.
I've created a Macro variable to my item, and the UI Macro which I've attached to the Macro.
Now I've created an onChange Catalog client script (I've set the isolate script to false) with a very simple script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
setDesc(newValue);
}
And to test it, a UI macro:
<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<div id="short_description"/>
<script>
function setDesc(text){
document.getElementById('short_description').innerHTML = text;
}
</script>
</j:jelly>
However when it's trying to invoke the setDesc()-function, an error is displayed in the console:
"Error while running Client Script "Display choice info text": ReferenceError: setDesc is not defined"
This must've worked at some point as I've found a couple of examples marked as correct, but can't get it to work now..
Example: how to call a ui macro from on change client script which(UI macro) should create dynamic input text...
Any ideas?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-26-2020 04:58 AM
I am afraid UI macros are not supported in Service Portal. However, you can link your Macro variable to a widget instead.
Blog: https://sys.properties | Telegram: https://t.me/sys_properties | LinkedIn: https://www.linkedin.com/in/slava-savitsky/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-14-2020 04:25 AM
Hi,
Please refer below links,It would help you out.
Please mark as correct and helpful,If you find any help worthy.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-14-2020 05:50 AM
Hi,
the code is working for me; Is the client script and UI macro in same scope
Are you hiding the macro variable on form load?
Mark ✅ Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-14-2020 06:42 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-15-2020 06:36 AM
This is very strange. I've cleared caches and all that, and thought that it might have to do with the on-premise instance I'm trying to get this to work, but no. I'm facing the same issue in my sandbox. Nothing here is scoped.