The CreatorCon Call for Content is officially open! Get started here.

Record producer script to assign an incident to one of two groups based on a multiple choice varable

Jason H1
Tera Contributor

Hi, 

I'm trying to have a record producer create an incident for one of two assignment groups based on the selection from a multiple-choice variable called phone_line_type. Here is the code:

 

(function () {
// Get the value of the 'phone_line_type' field
var phoneLineType = producer.phone_line_type;

// Define the sys_ids for the assignment groups
var assignmentGroup1 = 'sys_id_of_group_1';
var assignmentGroup2 = 'sys_id_of_group_2';

// Check if the assignment groups exist
var group1 = new GlideRecord('1f0ee795137867808b0d75c36144b018');
var group2 = new GlideRecord('2d993e78dbea99108d644641ba961926');
if (!group1.get(assignmentGroup1) || !group2.get(assignmentGroup2)) {
gs.addErrorMessage('One or both assignment groups do not exist. Please check the sys_ids.');
return;
}

// Create a new incident record
var incident = new GlideRecord('incident');
incident.initialize();

// Assign the incident to one of two groups based on the value of 'phone_line_type'
if (phoneLineType == 'analog_line') {
incident.assignment_group = assignmentGroup1;
} else if (phoneLineType == 'teams_call_line') {
incident.assignment_group = assignmentGroup2;
} else {
gs.addErrorMessage('Invalid phone line type. Please check the value of the phone_line_type field.');
return;
}

// Other incident fields can be set here, e.g.,
// incident.short_description = '...';
// incident.description = '...';

// Insert the new incident record
incident.insert();
})();
When I run this code, I see two errors: one is Record not found the other is Failed to create an incident with no Assignment Group 
 
Any idea where I need to improve here? I feel this should be easy to do.

 

 

1 ACCEPTED SOLUTION

Kishor O
Tera Sage

@Jason H1  Please try with the below code

var phoneLineType = producer.phone_line_type
if (phoneLineType == 'teams_call_line'); {
    current.assignment_group = '548cd3b48728a910c062fc48dabb35a1'; //sysid of assignment group
}
else if(phoneLineType == 'teams_call_line');{
 current.assignment_group = '788cd3b48728a910c062fc48dabb35a1'; //sysid of assignment group
}

View solution in original post

5 REPLIES 5

Kishor O
Tera Sage

@Jason H1  Please try with the below code

var phoneLineType = producer.phone_line_type
if (phoneLineType == 'teams_call_line'); {
    current.assignment_group = '548cd3b48728a910c062fc48dabb35a1'; //sysid of assignment group
}
else if(phoneLineType == 'teams_call_line');{
 current.assignment_group = '788cd3b48728a910c062fc48dabb35a1'; //sysid of assignment group
}

@Jason H1  let me know in which table you have created record producer ?

Hi @Kishor O  it's then incident table and its working now thanks

Yes that worked thanks