Help with assignment group e in record producer

Sonali01
Tera Contributor

Hello, new to ServiceNow  scripting. I have very slight experience with scripting, but not much. Anyway, what y user want is  I'm currently creating record producers. record producers automatically assign the assignment group based on the (user /requested for) region .
Example if user tim region is suncoast incident auto assign to assignment group Sn Suncoast, if user region is northeast incident assignment group is Sn Northeast.

below is my script , but its not working , any lead will be helpful as this a high priority.

// Get the user's record (assuming 'requested_for' is a reference to a user)

var user = producer.requested_for;

 

// Retrieve the region field from the user's record (assuming 'region' is a field on the user record)

var region = user.region.getDisplayValue();

 

// Initialize the assignment group variable

var assignmentGroup = '';

 

// Check if the region is empty (no region value assigned)

if (!region) {

    // If no region is assigned, use the default group

    assignmentGroup = 'SN Statewide Helpdesk';

} else {

    // Map regions to assignment groups (this will override the default if a region is found)

    if (region == 'Central') {

        assignmentGroup = 'SN Suncoast Desktop Support';  // Assign Suncoast group for Central region

    } else if (region == 'Suncoast') {

        assignmentGroup = 'SN Suncoast Desktop Support';

    } else if (region == 'Northwest') {

        assignmentGroup = 'Northeast';

    } else if (region == 'Northeast') {

        assignmentGroup = 'SN Northeast Desktop Support';

    } else if (region == 'Southern') {

        assignmentGroup = 'SN Southern Desktop Support';

    } else if (region == 'Southeast') {

        assignmentGroup = 'SN Southern Desktop Support';

    } else {

        // If region is unknown, default to SN Statewide Helpdesk

        assignmentGroup = 'SN Statewide Helpdesk';

    }

}




Thanks

 

 

 

 

 
 
3 REPLIES 3

Sujatha V M
Kilo Patron
Kilo Patron

@Sonali01 You may pass the sys id of the assignment groups. 

 

For e.g., 

 

Assuming you are getting the value of the "Region" field. 

 

if(region == ''){

current.assignment_group = '<sys_id_of_the_group>'; //Default group

}else if(region == 'Central'){

current.assignment_group = '<sys_id_of_the_group>'; //As per the condition

}
else{
current.assignment_group = '<sys_id_of_the_group>'; //Nothing matches
}

 

Passing the assignment group sys id, 

 

SujathaVM_0-1738952992097.png

 

On submission of the record producer, an incident is created with this assignment group

SujathaVM_1-1738953061391.png

 

Please mark this as helpful and accept it as a solution if this resolves your query.
Sujatha V.M.

Thanks Sujatha  sure will try and let you know.

Viraj Hudlikar
Giga Sage

Hello @Sonali01 

In your script you are initializing and setting value of group but that won't be set at all as there is no such field on your table where the record is inserted.


Over Record Producer in script when you want to set value of field you should have syntax like below:

 

current.assignment_group = 'sys_id_of_group';

 

 

If my response has helped you hit helpful button and if your concern is solved do mark my response as correct.

Thanks & Regards
Viraj Hudlikar.