Event Field mapping script

Soni Rahul
Tera Contributor

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 

(function eventFieldMappingScript(eventGr, origEventSysId, ciSysId, fieldMappingRuleName) {
    try {
     eventGr.setValue('assignment_group', '287ee6fea9fe198100ada7950d0b1b73');
     return true;
  } catch (e) {
     gs.error(" The script type mapping rule '" + fieldMappingRuleName + "' ran with the error: \n" + e);
  }

 })(eventGr, origEventSysId, ciSysId, fieldMappingRuleName);

Thanks

5 REPLIES 5

Mark Manders
Mega Patron

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

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

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

Vishal Jaswal
Giga Sage

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!