- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-18-2023 03:45 AM
Hi All,
I am working on a scenario where I can select multiple incidents in the list view and link them all with a single incident and this will create a record in the m2m table named[u_m2m_inc].
In order to achieve this, below is the UI action, UI page and Script Include
UI Page
---------------------
HTML
==============
<?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:evaluate var = "jvar_secrecords"
expression="RP.getWindowProperties().get('rec')" />
<input value = '${jvar_secrecords}' name = 'secRecords' type='hidden' id='misys'></input>
<label><b>Please select the Parent Incident Number</b></label><br></br>
<g:ui_reference name= "parent_incident" id="parent_incident" table = "incident" completer= "AJAXTableCompleter" query="active=true^u_linked_to_major_incident=false" ng-model= "parent_incident"/><br></br>
<button onclick = 'linkBulkTickets()'>Link</button>
</j:jelly>
=========
Client Script
=========
function linkBulkTickets() {
var ga = new GlideAjax('getIncDetails');
ga.addParam('sysparm_name', 'BulkLinkIncident'); //function in Script Include
ga.addParam('sysparm_bulksysids', gel('misys').value);
ga.addParam('sysparm_selectid', gel('parent_incident').value);
ga.getXMLAnswer(callback);
function callback(res) {
if (res) {
var listOfIds = gel('misys').value.toString();
var selectedlistOfIds = gel('parent_incident').value.toString();
//alert(listOfIds );
//alert(selectedlistOfIds);
if (!listOfIds.includes(selectedlistOfIds)) {
alert("The selected incidents have been linked successfully");
setTimeout(function() {
this.window.location.reload();
}, 300);
} else {
alert('Selected incident(Child incidents) are one of the Parent incident,Please select another incident as Parent Incident');
}
}
}
}
UI Action
----------------
function bulkUpdateMI() {
var checkSelectedRec = g_list.getChecked();
if (checkSelectedRec != '') {
alert('Are you sure all these incidents are related to Major Incidents?');
var gdw = new GlideDialogWindow('bulk_mi_link');
gdw.setPreference('rec', checkSelectedRec);
//'rec' -any keyword defined, 'checkSelectedRec' - passing selected record's sysids
gdw.render();
} else {
alert("Please select at least one record");
}
}
Script Incldues:
var getIncDetails = Class.create();
getIncDetails.prototype = Object.extendsObject(AbstractAjaxProcessor, {
BulkLinkIncident: function() {
var gasysIds = this.getParameter('sysparm_bulksysids');
var gaselid = this.getParameter('sysparm_selectid');
var gaspSys = gasysIds.split(',');
var gaSys1 = '';
for (var i = 0; i < gaspSys.length; i++) {
var grga1 = new GlideRecord('incident');
if (grga1.get(gaspSys[i])) {
var m2mInc = new GlideRecord("u_m2m_inc");
m2mInc.initialize();
m2mInc.u_linked_incident = gaselid;
//m2mInc.parent_incident = gasysIds;
m2mInc.u_incident = gasysIds;
m2mInc.u_added_by_business_rule = false;
m2mInc.insert();
if (gaSys1 != '') {
gaSys1 += ',' + grga1.update();
} else {
gaSys1 = grga1.update();
}
}
}
return gaSys1;
},
type: 'getIncDetails'
});
The issue is that when I select multiple incidents and try to link them, it creates a duplicate relationship of the same incident in the m2m table.(2 records with same details, it should be 2 records with 2 different incidents numbers which I selected rather it is creating 2 records with same incident numbers)
Could anyone please assist me in resolving this issue? Thanks
Mark this as Helpful / Accept the Solution if this helps.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-18-2023 04:36 AM
It seems like you should be using
gaspSys[i]
as the value to assign to either m2mInc.u_incident or m2mInc.u_linked_incident. Also try logging gasysIds to confirm that it contains the expected sys_ids.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-18-2023 04:36 AM
It seems like you should be using
gaspSys[i]
as the value to assign to either m2mInc.u_incident or m2mInc.u_linked_incident. Also try logging gasysIds to confirm that it contains the expected sys_ids.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-18-2023 05:04 AM
Thanks Brad for the prompt response. Yes, it worked.
Mark this as Helpful / Accept the Solution if this helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-18-2023 07:43 AM
Awesome, and you are welcome!