UI Action | UI page | Script Includes | Rendering variables sent from UI action on a UI Page HELP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-05-2023 01:59 AM - edited ‎10-05-2023 02:00 AM
Hello guys,
I'm using the 3 modules from the title. What I want to do is when UI action button is clicked I want the glideModalWindow to open and load the UI page that will show the records I have loaded from the Script Includes, I pretty much want to "print" out all the record names in the UI, (If I could do this I could do my full project, this is but a part to it)
My setup works partly, but I cannot get anything to "print" out on the UI page.
Script Includes
var CustomAjaxScript= Class.create();
CustomAjaxScript.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
getActionTemplates: function() {
var gr = new GlideRecord('incident'); // Assuming you're working with the 'incident' table
gr.query();
var action_templates = [];
while (gr.next()) {
action_templates.push(gr.number.getDisplayValue());
}
return JSON.stringify(action_templates);
},
type: 'CustomAjaxScript'
});
UI action
function modalPopUp() {
var ga = new GlideAjax('CustomAjaxScript'); // Assuming you have a Script Include named CustomAjaxScript
ga.addParam('sysparm_name', 'getActionTemplates'); // Specify the method you want to call in the Script Include
ga.getXML(populateModal);
}
function populateModal(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
if (answer) {
var answerParsed = JSON.parse(answer.toString());
console.log(typeof answer);
console.log(answer);
var a = [123,123,123]
var gm = new GlideModal("x_18087_qualitypoc_populate_via_template", false, 600);
gm.setTitle("Choose a Template");
gm.setPreference('text', 'hello'); // Sends the data into the UI page
gm.setPreference('action_templates', answer); // Sends the array as JSON
gm.setPreference('test_array', answerParsed); // Sends the array as JSON
gm.render();
// gsftSubmit(null, g_form.getFormElement(), "create_via_template");
} else {
alert("No data received from server.");
}
}
UI Page
<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<j:set var="action_templates" value="${action_templates}"></j:set>
<j:set var="test_array" value="${test_array}"></j:set>
<j:set var="array" value="${array}"></j:set>
<j:set var="jvar_msg_text" value="${text}"/>
<div class="modal-body">
<div>
<h1>HELLO</h1>
${jvar_msg_text}<br></br><br></br>
<j:forEach var="action" items='${action_templates}'>
${action}<br></br><br></br>
</j:forEach>
<j:forEach var="a" items='${test_array}'>
${a}<br></br><br></br>
</j:forEach>
${jvar_action_templates}
</div>
</div>
<script>
console.log('${action_templates}')
console.log('${test_array}')
</script>
<footer class="modal-footer flex">
<g:dialog_buttons_ok_cancel ok="return onOK();" cancel="return onCancel();" ok_type="button" cancel_type="button"/>
</footer>
</j:jelly>

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-05-2023 02:34 AM
Hi @Stefan Petkovic ,
You can get the properties set in the UI action, by using RP.getWindowProperties().<<propertyname>>;
RP.getWindowProperties().test_array;
RP.getWindowProperties().action_templates;
RP.getWindowProperties().text;
This article may help you:
Passing value from form to UI Page through UI Action (servicenowbuddies.blogspot.com)
Help others to find a correct solution by marking the appropriate response as accepted solution and helpful.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-05-2023 04:08 AM
I tried copying some of the code from the website you sent, and I keep getting the error :
The element type "g2:scope" must be terminated by the matching end-tag "</g2:scope>".
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-05-2023 02:35 AM
So you are able to send the value but you are not able to iterate that array in UI page?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-05-2023 03:52 AM
Exactly, I mean that's what I believe when I include the console.log(VARNAME) within the script tags in the ui action it prints nothing 😞