UI Action to assign Incidents to Problem
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-07-2024 09:04 AM
I would like to create a list choice UI Action on the Incidents table where a user can select multiple Incidents, then select "Assign to Problem" from the Actions on Selected Rows drop-down and then a List Choice box of all Problems will appear for the user to select a Problem and then the Incident.Problem value is updated with the Problem selected. Is this do-able?
See attached screen shot for more details (I created a UI Action called Assign to Problem but there's no code in it currently)
Thank you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-07-2024 09:16 AM
Hi @Tom Lapkowicz ,
Yes, You can it.
Do the following.
- Create UI action and make it client callable to run client side script.
- Create one ui page and design to select problem record.
- Use make of glideModel() to render ui page.
- Once user select problem on pop up and click on save call server side script.
- In server side UI action get the problem sys_id and update it to problem filed of incident.
-------------------------------------------------------------------------
If you found my response helpful, please consider selecting "Accept as Solution" and marking it as "Helpful." This not only supports me but also benefits the community.
Regards
Runjay Patel - ServiceNow Solution Architect
YouTube: https://www.youtube.com/@RunjayP
LinkedIn: https://www.linkedin.com/in/runjay
-------------------------------------------------------------------------
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-07-2024 10:47 AM
Thank you @Runjay Patel .
I'm not much of a coder, but using Chat GPT I came up with the coding below but it still doesn't seem to be working (it's not even prompting me for the Problem). Do you happen to see any glaring issues with the code? Thank you.
Script Includes (Client Callable box is checked):
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-08-2024 04:56 AM - edited ‎11-08-2024 04:59 AM
Hi @Tom Lapkowicz ,
I have spent lots of time to make this work for you. I have tested it, working fine. Just create below script as it is.
1. ui page
name: assign_problem_modal
HTML code
<?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:ui_form onsubmit="return invokeConfirmCallBack('Save');">
<div>
<label for="problem_id">Problem:</label>
<!-- <input type="text" id="problem_id" class="form-control" placeholder="Enter Problem Sys ID"></input> -->
<g:ui_reference name="QUERY:active=true" id="problem_id" table="problem" completer="AJAXTableCompleter" />
</div>
<div class="modal-footer">
<span class="pull-right">
<button class="btn btn-default" id="cancel_button" onclick="invokePromptCallBack('cancel')" style="min-width: 5em;" title="" type="submit">
Cancel
</button>
<button class="btn btn-primary" id="ok_button" onclick="invokePromptCallBack('Save')" style="min-width: 5em;" title="" type="submit">
Save
</button>
</span>
</div>
</g:ui_form>
</j:jelly>
Client Script Code:
function invokePromptCallBack(type) {
var gdw = GlideDialogWindow.get();
if (type == 'Save') {
var selectedIds = gdw.getPreference('selectedIds');
var problemId = document.getElementById('problem_id').value;
alert(selectedIds + problemId);
if (!problemId) {
alert("Please enter a valid Problem.");
return;
}
var ga = new GlideAjax('AssignIncidentsToProblem');
ga.addParam('sysparm_name', 'processInc');
ga.addParam('sysparam_sys_id', problemId);
ga.addParam('sysparam_inc_ids', selectedIds);
ga.getXML(serverResponse);
}
gdw.destroy();
return false;
}
function serverResponse(response) {
var answer = response.responseXML.documentElement.getAttribute('answer');
alert(answer);
location.reload();
}
2. UI Action
name: Assign to Problem
action name: assign_to_problem
code
function callMe() {
var selectedIds = GlideList2.get('incident').getChecked();
if (selectedIds.length === 0) {
alert("Please select at least one incident.");
return;
}
var modal = new GlideModal('assign_problem_modal');
modal.setTitle('Assign Problem to Selected Incidents');
modal.setPreference('selectedIds', selectedIds);
modal.render();
}
3. Script Include
name: AssignIncidentsToProblem
code
var AssignIncidentsToProblem = Class.create();
AssignIncidentsToProblem.prototype = Object.extendsObject(AbstractAjaxProcessor, {
processInc: function() {
var problemId = this.getParameter('sysparam_sys_id');
var incidentIds = this.getParameter('sysparam_inc_ids');
gs.log('Runjayp' + problemId + ' : ' + incidentIds);
// Process each selected incident
var incidentRecord = new GlideRecord('incident');
incidentRecord.addQuery('sys_id', 'IN', incidentIds);
incidentRecord.query();
var count = 0;
while (incidentRecord.next()) {
incidentRecord.problem_id = problemId; // Set the Problem ID
incidentRecord.update();
count++;
}
if (count > 0) {
return count + " incident(s) successfully assigned to Problem: ";
} else {
return "No incidents were updated.";
}
},
type: 'AssignIncidentsToProblem '
});
Output
-------------------------------------------------------------------------
If you found my response helpful, please consider selecting "Accept as Solution" and marking it as "Helpful." This not only supports me but also benefits the community.
Regards
Runjay Patel - ServiceNow Solution Architect
YouTube: https://www.youtube.com/@RunjayP
LinkedIn: https://www.linkedin.com/in/runjay
-------------------------------------------------------------------------
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-13-2024 07:50 AM
Hi @Runjay Patel . Thank you so much for your help on this! I set up the steps but apparently did not do something correct - "Assign to Problem" shows in the Actions on Selected Rows drop-down and it prompts to select the Problem, but then once a Problem is selected it goes to another screen asking for the Problem to be selected. I've attached screen shots of the UI Page, UI Action and Script Includes and the error. Any ideas what I'm doing wrong? Thanks!