Assignment group is not populating in Incident table

Dileep2
Tera Contributor

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.');
}

 

1 ACCEPTED SOLUTION

B_Engelstock
Tera Expert

Use this syntax (do not use sys_id in the field name):

current.assignment_group='d3059792131fd240adce3b27d144b07d';

View solution in original post

12 REPLIES 12

Ravi Chandra_K
Kilo Patron
Kilo Patron

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 

Hello @Dileep2

Were you able to do this.....

 

Kind Regards,

Ravi Chandra..

Mark Manders
Mega Patron

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

Ankur Bawiskar
Tera Patron
Tera Patron

@Dileep2 

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.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader