Event Field mapping script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-25-2025 04:21 AM
Hi All,
I have a one requirement to add the assignment group of alerts based on some conditions through the event field mapping script, right now for testing purpose I am just hardcoding the assignment group in script but it's not working so can you please help me how I can update the assignment group of alerts through event field mapping script.
Script
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-25-2025 06:56 AM
Assuming eventGR is the event this script is being called from, how are you setting 'assignment_group'? By my knowledge, events don't have assignment groups, or did you create a custom field for this?
What does your error give you in return?
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
‎03-25-2025 07:18 AM
Hi Mark,
Yes, events don't have any assignment group field, and I also didn't create any custom field for that. I was just asking is there a way we can update the assignment group of alerts through this event field mapping script.
There is no error for this, but it's not working.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-26-2025 01:01 AM
What is in the event that is not on the alert that you need to select the assignment group from? Why not just do it on the alert itself?
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
‎03-25-2025 08:05 AM
Hello @Soni Rahul
Here is your updated code:
/**
@Param eventGr - GlideRecord representing the event.
@Param origEventSysId - Id of the event.
The GlideRecord event parameter is a temporary object, and therefore does not contain the id of the original event.
@Param fieldMappingRuleName - The name of this field mapping rule.
*/
(function eventFieldMappingScript(eventGr, origEventSysId, fieldMappingRuleName) {
// Make any changes to the alert which will be created out of this Event
// Note that the Event itself is immutable, and will not be changed in the database.
// You can set the values on the eventGr, e.g. eventGr.setValue(...), but don't perform an update with eventGr.update().
// To abort the changes in the event record, return false;
// Returning a value other than boolean will result in an error
try {
// Write your code here
var alertNum = eventGr.getValue('alert');
var grAlert = new GlideRecord('em_alert');
grAlert.addQuery('number', alertNum);
grAlert.query();
if (grAlert.next()) {
//Create a system property in sys_property with value as the sys_id of the assignment group as it is not good practice to hardcode sys_id on a reference field as it will be red flag during Instance scan
var assignmentGroupSysId = gs.getProperty('assignment.group.network');
if (assignmentGroupSysId) {
grAlert.assignment_group = assignmentGroupSysId;
grAlert.update();
} else {
gs.error("System property 'assignment.group.network' is not set or invalid.");
}
}
return true;
} catch (e) {
gs.error("The script type mapping rule '" + fieldMappingRuleName + "' ran with the error: \n" + e);
return false;
}
})(eventGr, origEventSysId, fieldMappingRuleName);
Hope that helps!