Looking for an example of "Advanced mapping using script" for event field mapping

gaurav4sn
Tera Contributor

Hi All,

 

I wanted to use "Advanced mapping using script" for event field mapping. can any one provide me any script for same. I am not able to figure out how to choose source and target field.

 

Actually we are getting lots of data in our additional info , and we wanted to extract the data on a specific condition and map that data in target field.

 

Thanks

3 REPLIES 3

Paul38
Tera Guru

Hello,

From what I understood the Advanced mapping using script option does not work like a Field map script where you can select the source and target.

 

What you can do is change the event data before the Transform and Compose or after the CI binding. The event record in the DB will not be modified and any changes you do are on a temporary event object.

Below you can find an example of what I used to get data from a custom field from the Additional info and map it to other parameters or fields.

(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 {
		var addInfo = JSON.parse(eventGr.getValue("additional_info"));
		if (addInfo.hasOwnProperty("CustomField1")) {
			var customFieldValues = addInfo["CustomField1"].split(" ");
			addInfo.ars_esc = customFieldValues[0].trim() === "escalate" ? "Yes" : "No";
			addInfo.ars_delay_time = customFieldValues[2].trim();
			eventGr.setValue("additional_info", JSON.stringify(addInfo));
			switch (customFieldValues[1].trim()) {
				case "Low":
					eventGr.setValue("severity", 4);
					break;
				case "Medium":
					eventGr.setValue("severity", 3);
					break;
				case "High":
					eventGr.setValue("severity", 2);
					break;
				case "Critical":
					eventGr.setValue("severity", 1);
					break;
			}
		}
		return true;
	} catch (e) {
		gs.error(" The script type mapping rule '" + fieldMappingRuleName + "' ran with the error: \n" + e);
	}
})(eventGr, origEventSysId, fieldMappingRuleName);

 
Hope this helps!
Paul

SSakkirala
Tera Contributor

I am trying to setup severity as mentioned in the above script. But the severity on the event record isnt updating. Its stuck with "None". I am not using eventGr.update(), but just eventGr.setvalue() isnt working. Any suggestions on that?

Kevin_Bufford
Giga Contributor

Check field permissions: make sure the script has the proper permissions to modify the severity field and that it is not read-only in the context of the event. The field may be locked for editing due to certain conditions, such as record status or security settings. Also check that the user has the appropriate permissions to edit the field. If the field is read-only, change these settings or use another method to update it