- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-28-2025 02:15 AM - edited 03-13-2025 08:14 PM
Hi Experts,
I have a requirement. On an incident form we have a field called "Caused By Change". The requirement is on the closed incidents we need to created a button when clicked, opens a pop-up or modal and that window should populate the incident form "Caused By Change" value. if Caused by change is not having any value then we need to select existing Change Requests. I tried this by creating a UI action, UI page and called script include in the client script of UI page. However there is no luck. Need your expertise here. I cant paste the code here due to our project restriction. Its little critical
Thanks in advance.
@Ankur Bawiskar I saw you helped many people need your advice here as well.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-28-2025 04:18 AM
this worked for me
Send the sysId and display value as well and set both
function showModal() {
var gm = new GlideDialogWindow('showchangerequest');
gm.setTitle('My UI page');
gm.setSize(600,600); //Set the dialog size
gm.setPreference('sysparm_changesysid', g_form.getValue('caused_by'));
gm.setPreference('sysparm_changenumber', g_form.getDisplayBox('caused_by').value);
gm.render();
}
Please enhance from your side.
<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<html>
<g:ui_form>
<g:evaluate var="jvar_changeSysId" expression="RP.getWindowProperties().get('sysparm_changesysid')" />
<g:evaluate var="jvar_changenumber" expression="RP.getWindowProperties().get('sysparm_changenumber')" />
<input type="hidden" id="changerequest1" name="changerequest1" value="${jvar_changeSysId}"></input>
<div id='mydiv3'>
<label id='label3'>Change Request</label>
<g:ui_reference name="changerequest" id="changerequest" table="change_request" value="${jvar_changeSysId}" displayValue="${jvar_changenumber}" style="width:180px"/>
</div>
</g:ui_form>
</html>
</j:jelly>
Output:
I hope I have answered your question and you can enhance it further
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-28-2025 04:09 AM
how did the CI auto populate?
Is that logic already there in UI page?
If yes then simply use the same.
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-28-2025 08:27 AM
Hi Ankur,
CI autopopulation was done in problem form and its OOB one. I even checked the script they are calling a UI Script into UI action. That UI script I didnt even understand its very high level. However the solution you gave at the end worked well. One last help can you please explain me the below line of code that you have used in HTML of UI page.
<g:ui_form> <g:evaluate var="jvar_changeSysId" expression="RP.getWindowProperties().get('sysparm_changesysid')" /> <g:evaluate var="jvar_changenumber" expression="RP.getWindowProperties().get('sysparm_changenumber')" /> <input type="hidden" id="changerequest1" name="changerequest1" value="${jvar_changeSysId}"></input>
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-28-2025 04:18 AM
this worked for me
Send the sysId and display value as well and set both
function showModal() {
var gm = new GlideDialogWindow('showchangerequest');
gm.setTitle('My UI page');
gm.setSize(600,600); //Set the dialog size
gm.setPreference('sysparm_changesysid', g_form.getValue('caused_by'));
gm.setPreference('sysparm_changenumber', g_form.getDisplayBox('caused_by').value);
gm.render();
}
Please enhance from your side.
<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<html>
<g:ui_form>
<g:evaluate var="jvar_changeSysId" expression="RP.getWindowProperties().get('sysparm_changesysid')" />
<g:evaluate var="jvar_changenumber" expression="RP.getWindowProperties().get('sysparm_changenumber')" />
<input type="hidden" id="changerequest1" name="changerequest1" value="${jvar_changeSysId}"></input>
<div id='mydiv3'>
<label id='label3'>Change Request</label>
<g:ui_reference name="changerequest" id="changerequest" table="change_request" value="${jvar_changeSysId}" displayValue="${jvar_changenumber}" style="width:180px"/>
</div>
</g:ui_form>
</html>
</j:jelly>
Output:
I hope I have answered your question and you can enhance it further
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-28-2025 02:22 AM
Hello @bhaavani ,
You are in the correct approach you need ui action,ui page & script inlude to achieve this the below is samples for the requirement please try the below scripts and amend it according to your requirement and backend names.
UI Action:
// This UI Action will call the UI Page
action.setRedirectURL('/x_your_instance_namespace/ui_page_name.do?sys_id=' + g_form.getUniqueValue());
UI Page:
<g:ui_page>
<html>
<head>
<!-- Include necessary libraries -->
</head>
<body>
<!-- Display Caused By Change value -->
<span id="causedByChange"></span>
<!-- If empty, show change request list -->
<div id="changeRequestList"></div>
</body>
<script type="text/javascript">
// Client script to fetch data and populate the UI
var incidentId = g_request.getParameter('sys_id');
fetchCausedByChange(incidentId);
function fetchCausedByChange(incidentId) {
var ga = new GlideAjax('YourScriptInclude');
ga.addParam('sys_id', incidentId);
ga.addParam('method', 'getCausedByChange');
ga.getXMLAnswer(processCausedByChange);
}
function processCausedByChange(response) {
var causedByChange = response;
if (causedByChange) {
document.getElementById('causedByChange').innerText = causedByChange;
} else {
fetchChangeRequests();
}
}
function fetchChangeRequests() {
var ga = new GlideAjax('YourScriptInclude');
ga.addParam('method', 'getChangeRequests');
ga.getXMLAnswer(processChangeRequests);
}
function processChangeRequests(response) {
// Populate the change request list in the modal
document.getElementById('changeRequestList').innerHTML = response;
}
</script>
</html>
</g:ui_page>
Script Include:
var YourScriptInclude = Class.create();
YourScriptInclude.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getCausedByChange: function() {
var sysId = this.getParameter('sys_id');
var incident = new GlideRecord('incident');
incident.get(sysId);
return incident.getValue('caused_by_change') || '';
},
getChangeRequests: function() {
var changeList = '';
var changeRequest = new GlideRecord('change_request');
changeRequest.query();
while (changeRequest.next()) {
changeList += '<option value="' + changeRequest.sys_id + '">' + changeRequest.number + '</option>';
}
return changeList;
}
});
Please mark it as helpful/correct if this resolves/helps you.
Regards,
Debasis
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-28-2025 03:00 AM
Hi Debasis,
Thanks for your response. Let me try this approach. However I have a query in the below UI action. And the UI action should not be client callable right ? and how can we give the onclick function ?
x_your_instance_namespacen for example my dev instance name is: abcdev.service-now.com if we give like this the how it will work in other environments like uat and prod ?