Script include inbound action gliderecord issue
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-13-2024 12:16 AM
Hi All,
I have a SI called by an inbound action that is not working right when it gets to the sys_user_group table query the group is not found but it is 100% there for sure. Could someone review the code please.
var AssignIncidentToGroup = Class.create();
AssignIncidentToGroup.prototype = {
initialize: function() {
},
assignToGroup: function(email) {
// Get the list of recipient email addresses
var recipientEmails = email.to.split(',');
gs.log('EliTest recipients: ' + recipientEmails);
// Define a mapping of email addresses to assignment groups
var assignmentGroupMapping = {
'uhd.help@test.de': 'UHD',
'sap.help@test.de': 'IT-SAP',
'help@test.de': 'IT- Sales Support'
};
// Count the matches in the recipient field
var matchCount = 0;
var lastMatchedGroup = '';
for (var i = 0; i < recipientEmails.length; i++) {
var recipientEmail = recipientEmails[i].trim();
if (assignmentGroupMapping[recipientEmail]) {
matchCount++;
lastMatchedGroup = assignmentGroupMapping[recipientEmail];
gs.log('EliTest Matched Group: ' + lastMatchedGroup + ' Match Count: ' + matchCount);
}
}
// Determine the assignment group based on the number of matches
var assignmentGroupName = '';
if (matchCount >= 2) {
assignmentGroupName = assignmentGroupMapping['help@test.de'];
} else if (matchCount === 1) {
assignmentGroupName = lastMatchedGroup.trim();
gs.log('EliTest after match count1 : assignmentGroupName is ' + assignmentGroupName);
}
// Initialize groupSysId
var groupSysId = '';
if (assignmentGroupName) {
gs.log('EliTest gr1st find group ' + assignmentGroupName); // has correct group
var gr = new GlideRecord('sys_user_group');
gr.addQuery('name', assignmentGroupName); // does not find group but group exist for sure
gr.query();
if (gr.next()) {
gs.log('EliTest Found group sys_id: ' + gr.assignmentGroupName);
groupSysId = gr.sys_id;
} else {
gs.log('EliTest No group found for name: ' + assignmentGroupName);
}
}
// Create or update the incident
if (groupSysId) {
current.assignment_group = groupSysId;
current.description = email.body_text;
current.short_description = email.subject;
current.update();
} else {
gs.log('EliTest No matching assignment group found for recipient: ' + email.to);
}
},
type: 'AssignIncidentToGroup'
};
0 REPLIES 0