How to Re-render UI Page in a catalog item

Michael M1
Giga Expert

One of the variables/questions on my catalog item is a UI Page.

This UI Page performs a var gr query to get the url of an image and displays it on the page.

It works fine on loading.

When I change a choice in another field - which is a drop down list - I want to call the UI Page again to get the new image for display.

How do I get the UI Page to update? If I use an onChange client script I can't seem to figure out the code that works here.

6 REPLIES 6

kristenankeny
Tera Guru

I created a very basic set up. I have two variables on a form. One is a select with the choices first and second. The second is a macro variable that points to a macro that only contains script. (I haven't been able to find a way to pass the variable from the script to any jelly variables). Then, there is a client script that runs on change of my select variable.

Select variable options:

find_real_file.png

On change client script running against the select variable:

find_real_file.png

 

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">
	<script>
		function myChoice(sentChoice){
			if(sentChoice == 'first'){
				document.getElementById("demo").innerHTML = "First!";
			}
			else if(sentChoice == 'second'){
				document.getElementById("demo").innerHTML = "Second!";
			} 
			var choice = sentChoice;
		}
	</script>
	<p id="demo"></p>
</j:jelly>

 

Thanks.

You said: "(I haven't been able to find a way to pass the variable from the script to any jelly variables)."

But you are passing newValue via function no?

This is my problem I believe.

I need to send a parameter in a drop down list to the UI Page so that it can change the icon based on the selected choice.

ChrisBurks
Giga Sage

Once the page is rendered you should interact with the UI page with normal javascript if you're trying to change a client side item such as an icon. 
Here is an example:
find_real_file.png

UI page HTML/XML:

<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">

    <h3>UI Page Items Below</h3>
    <hr/>
    <span id="icon1" class="icon-clear" style="font-size: 24px"> <span>User</span></span>
	

</j:jelly>

 

Catalog Client Script:

function onChange(control, oldValue, newValue, isLoading) {

   if (isLoading) {
	   
      return;
   }
	
   var sample = document.getElementById('icon1');
   if(newValue == ''){
	sample.className = '';
	sample.classList.add('icon-clear');
	return;
   }

   sample.className = '';
   sample.classList.add(newValue);

}

// Any of these techniques would work too:
// var sample = gel('icon1');
// var sample = $j('#icon1')[0];
// var sample = g_form.getElement('icon1');
// var sample = icon1;

So I have a catalog script as:

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading) {
return;
}

var sample = document.getElementById('app_icon');
g_form.addInfoMessage("Element sample = "+sample+" new value = "+newValue);

}

Just to see what info I get and nothing gets put on the screen - I assume it errors out.

The catalog question/variable is of Type = UI Page with name = app_icon.

The UI Page is defined as:

<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<g:evaluate>
var myurl = "https://X.service-now.com/5389b32bdbf3a704ed2d8a503996194a.iix";

var gr = new GlideRecord("u_x_appstore");
gr.addQuery("u_application", u_xapp);
gr.query();
if (gr.next()) {
var myurl = gr.u_app_icon_url;
}
</g:evaluate>

<img src="${myurl}" height="125" width="125" />
</j:jelly>

 

In my table there are attributes for u_xapp = name of application (e.g. AutoCad), u_icon = uploaded image reference, u_icon_url = internal URL for the saved image.

 

So above - is my UI Page a document element that can be accessed? 

Should I change the method being used to something other than UI page?