How to call UI macro with a parameter from Catalog client script

emaasalmi
Kilo Sage

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?

1 ACCEPTED SOLUTION
8 REPLIES 8

Slava Savitsky
Giga Sage

Where are you trying to get it to work: in the Platform UI or in Service Portal?

How do you embed your macro into the page?

Is the DIV element from your macro present in the code of the page?

In Service Portal. I've added a Macro type of variable and selected the UI macro in the variable's Type specifications tab. Can't really see anything from the macro on the service portal. Not even hard coded labels.

Thanks Slava for confirming this. I had already abandoned the use of macro anyways, and now use field messages instead, even though they don't support html formatting.