Call a UI Script from a UI Page's Client Script

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-20-2017 11:32 AM
I have a custom HighChart template that I re-use for several graphs. I make the graphs available to my homepage through a UI Page referenced by a System UI Widget.
This is an abridged version of the code for the HighChart:
Highcharts.setOptions({
lang: {
thousandsSep: ','
}
});
var ga = new GlideAjax('MyChartUtil');
ga.addParam('sysparm_name', 'getData');
ga.addParam('sysparm_metric', 'CountsDaily');
ga.getXMLWait();
ga.getXML(parseResponse);
function parseResponse(response) {
var weekday = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"][new Date().getDay()];
var data = response.responseXML.documentElement.getAttribute("answer").evalJSON();
var cX = new Date().getHours() + 1;
var cY = data['span'][cX][1];
data['span'][cX][1] = null;
var chart = new Highcharts.Chart({
chart: {
renderTo: data['renderto'],
type: 'spline'
},
xAxis: {
tickInterval: 2
},
yAxis: {
title: false,
gridLineColor: 'rgba(0,0,0,0.1)',
gridZIndex: -1,
min: 0
},
series: [{
type: 'areasplinerange',
name: 'Typical ' + weekday + ' Range',
data: data['range'],
lineWidth: 0,
color: '#2f7ed8',
fillOpacity: 0.25,
enableMouseTracking: false,
marker: {
enabled: false
}
}]
});
}
The UI Page is really just a stub. I use it for several graphs. I would like to create a Javascript Object that I can call on demand that would hold all of this, rather than creating copies on every relevant UI Page. This is really simple on the server-side with a Script Include. It seems like a UI Script is what I want on the client-side, but I don't see how to instantiate it on the UI Page.
Has anyone attempted this before? Ideas?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-20-2017 03:49 PM
Yes, UI Script is the way to go. I would recommend creating your object in a UI script, but do not make it global. You can include that UI script in your UI page with this jelly tag:
<g:requires name="[ui script name].jsdbx" />
Then, you can call your script from there.
Does that answer your question
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-30-2018 10:59 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-30-2018 11:05 PM
use global before calling ui script.
like global.yourUI_script_name.