- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2024 02:25 AM
Hi All,
I have created Inbound email action and with the help of attached script by sending email, I can create new records in the Incident table with all the values except assignment group.
Please suggest
var emailSubject = email.subject; // Get the subject line of the email
var callerEmail = emailSubject.match(/[a-zA-Z0-9._%+-?#]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}/)[0]; // Extract email using regex
// Look up user based on the email address
var user = new GlideRecord('sys_user');
user.addQuery('email', callerEmail); // Query for user with the extracted email
user.query();
var incidentSysID; // Declare the incident Sys ID variable
if (user.next()) {
// User found, proceed to set the caller and affected user
current.caller_id = user.sys_id;
current.u_affected_user = user.sys_id;
current.priority = 3;
current.short_description = email.subject;
current.description = email.body_text;
current.location = gs.getUser().getLocation();
current.u_phone = gs.getUser().getRecord().getValue('phone');
//current.assignment_group = 'd3059792131fd240adce3b27d144b07d';
//current.assignment_group = "KRONOS - US";
//current.assignment_group.sys_id='d3059792131fd240adce3b27d144b07d';
current.assignment_group.name = "KRONOS - US";
//current.assignment_group.setDisplayValue('KRONOS - US');
current.insert();
} else {
gs.info('User with email ' + callerEmail + ' not found.');
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2024 06:01 AM
Use this syntax (do not use sys_id in the field name):
current.assignment_group='d3059792131fd240adce3b27d144b07d';
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2024 02:32 AM - edited 12-12-2024 03:42 AM
Hello @Dileep2
Replace the below line with current. assignment_group = 'sys_id' //sys id of the group.
(You can store this sys_id in system property and call the same property using gs.getProperty('property name');
current.assignment_group.name = "KRONOS - US";
you are trying to dot walk on assignment group name and update the name, it doesn't work as assignment group is a reference field type which holds the reference of the record (sys_id)
Please mark the answer as helpful and correct if helped.
Kind Regards,
Ravi Chandra
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2024 08:13 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2024 02:48 AM
Assignment group is a reference field, so you need to put the sys_id in there. It won't work with the name (or you create a script to find the sys_id by scripting to the sys_user_group table where name is the name of your group).
I do advise you to look at inbound email flows. They are way easier to configure. You just fill in the values and the flow makes sure the ticket gets created. No need for scripting at all.
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
12-12-2024 03:35 AM
if you are sure the group name is correct & is always unique; then update this line and it will work
current.assignment_group.setDisplayValue("KRONOS - US");
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader