- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-12-2024 01:54 AM - edited 08-12-2024 02:21 AM
Hello,
Could anyone please help me on this as i need to set the assignment group based on the subject line of incident.
I have created one table and there i stored subject and assignment group.I have created the inbound action for 'Create Incident'.
Below is the code.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-12-2024 07:17 AM
Hi @Mansi roy
Try bellow refined script once and test:
// Set the caller and basic details from the email
current.caller_id = gs.getUserID();
current.comments = "received from: " + email.origemail + "\n\n" + email.body_text;
current.short_description = email.subject;
// Set incident state, notify and contact type
current.incident_state = IncidentState.NEW;
current.notify = 2;
current.contact_type = "email";
// Assign incident if specified in the email body
if (email.body.assign != undefined) {
current.assigned_to = email.body.assign;
}
// Set priority based on email importance
if (email.importance != undefined) {
current.priority = 1;
}
// Normalize the subject for searching
var subject = email.subject.toLowerCase();
// Query the subject group mapping table
var mapping = new GlideRecord('u_subject_group_mapping');
mapping.addQuery('u_subject', subject);
mapping.query();
if (mapping.next()) {
// If a mapping is found, set the assignment group
var assignmentGroup = mapping.u_assignment_group;
if (assignmentGroup) {
current.assignment_group = assignmentGroup;
} else {
gs.info('No assignment group found for the subject: ' + subject);
}
} else {
gs.info('No mapping found for the subject: ' + subject);
}
// Insert the new incident record
current.insert();
Also keep consider the point mentioned by Ankur, here I am assuming 'assignment group' field is reference field in your custom table.
I hope my answer helps you to resolve your issue, if yes mark my answer correct & helpful.
thank you
rajesh.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-13-2024 02:21 AM
@Mark Manders ,Could you please help me with the code as i am getiing confised how to achieve.It will be very helpful.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-13-2024 02:35 AM
var subject = email.subject.toLowerCase(); // validate that you only have lower case in your custom table!!!
var mapping = new GlideRecord('u_subject_group_mapping');
mapping.addQuery('u_keyword', subject);
mapping.query();
if (mapping.next()) {
var assignmentGroup = new GlideRecord('sys_user_group');
assignmentGroup.addQuery('name',mapping.u_assignment_group);
assignmentGroup.query();
if (assignmentGroup) {
//current.assignment_group = assignmentGroup;
current.assignment_group = assignmentGroup.getUniqueValue();
} else {
gs.info('No assignment group found for the subject: ' + subject);
}
} else {
gs.info('No mapping found for the subject: ' + subject);
}
Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-13-2024 06:28 AM
After i updated this code now incident is not getting created. Email is getting recieved. Could you please check the below code once.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-12-2024 05:49 AM
hi @Mansi roy
I hope you have stored 'subject' of mails in lower case in your custom table.
Also please confirm, are you getting 'assignmentGroup' value here??
var subject = email.subject.toLowerCase();
var mapping = new GlideRecord('u_subject_group_mapping');
mapping.addQuery('u_keyword', 'LIKE', subject);
mapping.query();
var assignmentGroup = null;
if (mapping.next()) {
assignmentGroup = mapping.u_assignment_group; // ARE YOU GETTING 'assignmentGroup' VALUE HERE??
}
if yes(you getting value of assignmentGroup) then you need not to glide to 'incident' table, just add value of assignmentGroup to your incident assignment group as bellow:
current.assignmentGroup = assignmentGroup;
if (assignmentGroup)
var incident = new GlideRecord('incident'); // AVOID THIS GLIDE RECORD
if (incident.get(email.reference)) {. // AVOID THIS
incident.assignment_group = assignmentGroup; // REPLACE HERE - "current.assignment_group = assignmentGroup"
incident.update(); // AVOID THIS
}
else {
gs.info ('No assignment group found for the subject: ' + subject);
}
}
i hope my answer helps you to resolve your issue, if yes mark my answer helpful and correct.
THANK YOU
rajesh.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-12-2024 06:56 AM
Hello Rajesh,
I am not getting value here.
anything wrong i did in the script. Please let me know.