Event Management

Mark Wood
Tera Contributor

Hello experts,


I have created one choice field whose name is a MA category with two choices default and remote on em_event.and another choice field I have made on em_alert whose name is also a MA category with same choices.
I know there is already a category field on the alert form. I am exploring custom field mapping that's is why I am doing this.
in my event rule, I have mapped the alert MA category and MA event category.
but the same category is not getting populated on the alert record. it's showing me "<<unknown>>".

I have read below two articles and attached a screenshot of the mapping.

 

 

How to add new custom field to Transform and Compose section of Event Rule / How to popuate custom A...

 

Custom alert fields (servicenow.com)


please guide me.
thank you.

1 REPLY 1

Tushar
Kilo Sage
Kilo Sage

Hi @Mark Wood 

 

The reason why the category is not getting populated on the alert record is because the custom field mapping is not being triggered. The custom field mapping is only triggered when the event is created.

In your case, the event is already created before the alert is created.

To fix this, you can use the after_insert trigger on the em_alert table.

The after_insert trigger will be triggered after the alert record is created. In the after_insert trigger, you can update the category field with the value of the MA category field.

 

Here is an sample code of how you can use the after_insert trigger to update the category field:

function after_insert(table_name, id) {
  if (table_name == 'em_alert') {
    var alert = new GlideRecord('em_alert', id);
    var maCategory = alert.getFieldValue('u_ma_category');
    alert.setFieldValue('category', maCategory);
    alert.update();
  }
}

 

This code will create a new GlideRecord for the alert record with the ID that is passed to the function.

The code will then get the value of the u_ma_category field and set the value of the category field to the value of the maCategory field.

Finally, the code will update the alert record.

 

 

 

Please, don't forget to mark my answer as correct if it solves your issue or mark it as helpful if it is relevant for you!

Regards,
Tushar