- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-24-2023 09:56 PM - edited ‎07-24-2023 09:57 PM
I have a UI action button that opens a GlideDialogWindow popup. content of this popup comes from a UI page. The UI page has 2 fields and values of these are sent to a Script include through GlideAjax when user clicks on submit button in popup. The script include creates a new incident based on values.
want to close the popup (working fine) after clicking button in the popup and redirect to the newly created incident (to be done). action.setRedirectURL(<>) does nothing.
How to do so ? where to write the code ? Ui action or script include ?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-25-2023 12:33 AM
Hi @Snehal13 ,
Here's a general outline of how you can achieve this:
- In your UI action, open the GlideDialogWindow popup that contains the UI page.
- In the UI page, handle the form submission using GlideAjax to send the data to the Script Include and create the new incident.
- In the GlideAjax response handler, after the new incident is created, set the redirect URL using "window.location.href" to navigate to the newly created incident's form.
Here's a code example:
-->>UI Action:
function openPopup() {
var dialog = new GlideDialogWindow('popup_page');
dialog.setTitle('Popup Title');
dialog.setPreference('sysparm_my_param', 'my_value'); // Pass any preferences if needed
dialog.render();
}
-->>UI Page (popup_page):
<!DOCTYPE html>
<html>
<head>
<title>Popup Page</title>
</head>
<body>
<form id="myForm">
<!-- Your form fields here -->
<input type="text" name="field1" id="field1">
<input type="text" name="field2" id="field2">
<input type="button" value="Submit" onclick="submitForm()">
</form>
<script>
function submitForm() {
var field1Value = document.getElementById('field1').value;
var field2Value = document.getElementById('field2').value;
var ga = new GlideAjax('script_include_name');
ga.addParam('sysparm_name', 'createIncident');
ga.addParam('sysparm_field1', field1Value);
ga.addParam('sysparm_field2', field2Value);
ga.getXML(handleResponse);
}
function handleResponse(response) {
var newIncidentID = response.responseXML.documentElement.getAttribute('answer');
if (newIncidentID) {
// Redirect to the newly created incident
window.location.href = '/incident.do?sys_id=' + newIncidentID;
} else {
alert('Incident creation failed.');
}
// Close the popup after redirecting
GlideDialogWindow.get().destroy();
}
</script>
</body>
</html>
-->>Script Include (script_include_name):
var ScriptIncludeName = Class.create();
ScriptIncludeName.prototype = {
initialize: function() {},
createIncident: function() {
var field1=this.getParameter('sysparm_field1');
var field2=this.getParameter('sysparm_field2');
var newIncident = new GlideRecord('incident');
newIncident.initialize();
newIncident.short_description = 'New Incident'; // Set any desired values
//newIncident.field1=field1;
//newIncident.field2=field2;
newIncident.insert();
return newIncident.sys_id.toString();
},
type: 'ScriptIncludeName'
};
Make sure to replace 'popup_page' with the correct name of your UI page and 'script_include_name' with the actual name of your Script Include. Adjust the form fields and the incident creation logic as per your requirement.
This way, after the user submits the form in the popup, the incident will be created, and the popup will be closed. The user will be redirected to the newly created incident.
Thanks,
Ratnakar

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-24-2023 10:03 PM
is your UI Action running on client side or server side?
Share the UI Action code
Harish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-25-2023 12:33 AM
Hi @Snehal13 ,
Here's a general outline of how you can achieve this:
- In your UI action, open the GlideDialogWindow popup that contains the UI page.
- In the UI page, handle the form submission using GlideAjax to send the data to the Script Include and create the new incident.
- In the GlideAjax response handler, after the new incident is created, set the redirect URL using "window.location.href" to navigate to the newly created incident's form.
Here's a code example:
-->>UI Action:
function openPopup() {
var dialog = new GlideDialogWindow('popup_page');
dialog.setTitle('Popup Title');
dialog.setPreference('sysparm_my_param', 'my_value'); // Pass any preferences if needed
dialog.render();
}
-->>UI Page (popup_page):
<!DOCTYPE html>
<html>
<head>
<title>Popup Page</title>
</head>
<body>
<form id="myForm">
<!-- Your form fields here -->
<input type="text" name="field1" id="field1">
<input type="text" name="field2" id="field2">
<input type="button" value="Submit" onclick="submitForm()">
</form>
<script>
function submitForm() {
var field1Value = document.getElementById('field1').value;
var field2Value = document.getElementById('field2').value;
var ga = new GlideAjax('script_include_name');
ga.addParam('sysparm_name', 'createIncident');
ga.addParam('sysparm_field1', field1Value);
ga.addParam('sysparm_field2', field2Value);
ga.getXML(handleResponse);
}
function handleResponse(response) {
var newIncidentID = response.responseXML.documentElement.getAttribute('answer');
if (newIncidentID) {
// Redirect to the newly created incident
window.location.href = '/incident.do?sys_id=' + newIncidentID;
} else {
alert('Incident creation failed.');
}
// Close the popup after redirecting
GlideDialogWindow.get().destroy();
}
</script>
</body>
</html>
-->>Script Include (script_include_name):
var ScriptIncludeName = Class.create();
ScriptIncludeName.prototype = {
initialize: function() {},
createIncident: function() {
var field1=this.getParameter('sysparm_field1');
var field2=this.getParameter('sysparm_field2');
var newIncident = new GlideRecord('incident');
newIncident.initialize();
newIncident.short_description = 'New Incident'; // Set any desired values
//newIncident.field1=field1;
//newIncident.field2=field2;
newIncident.insert();
return newIncident.sys_id.toString();
},
type: 'ScriptIncludeName'
};
Make sure to replace 'popup_page' with the correct name of your UI page and 'script_include_name' with the actual name of your Script Include. Adjust the form fields and the incident creation logic as per your requirement.
This way, after the user submits the form in the popup, the incident will be created, and the popup will be closed. The user will be redirected to the newly created incident.
Thanks,
Ratnakar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-26-2023 06:56 AM
Thanks a ton. I have already implemented the GlideAjax flow and able to create incident. Was missing the response handling part - to redirect. will plug this.