Opsgenie - Transform Map script help

Community Alums
Not applicable

Hi All,

I have a working Opsgenie integration with ServiceNow.

I have tried to create various business rules to customise this but when they are switched on it breaks some elements of the integration.

So I would like to customise the transform map script on create to match my requirements but I need some help.

Requirements -

  1. If short descriptions contains 'failed order' then assignment group should be 'Draw Team'
  2. If short description contains 'failed order' add URL link below the existing description.
  3. If short description contains 'incoming call' set state to closed with resolution note 'no action required' and resolution code 'no fault found'.

Current 'Create' script -

(function transformRow(source, target, map, log, isUpdate) {
	var client = new OpsGenie_Client();
	var groupName = source.u_assigned_group;
	target.opened_by = "8dcf46881b922c105f562f0a2d4bcbef";
	target.caller_id = "8dcf46881b922c105f562f0a2d4bcbef";
	target.location = "0ef8a2af1b753c507c7e4046b04bcbeb";
	target.category = "Application";
	target.subcategory = "Internal Application";
	target.business_service = "9a1f8a481b922c105f562f0a2d4bcb77";
	target.u_incident_type = "Incident";
	target.assignment_group = "0626982cdb4d2410d2178a5039961952";
	target.x_86994_opsgenie_opsgenie_alert_id = "https://site.app.opsgenie.com/alert/detail/" + source.u_opsgenie_alert_id + "/details";

Hoping I can achieve all of this within this one script.

Any help would be much appreciated.

Thanks!
Alex

1 ACCEPTED SOLUTION

(function transformRow(source, target, map, log, isUpdate) {
	var client = new OpsGenie_Client();
	var groupName = source.u_assigned_group;
	target.opened_by = "8dcf46881b922c105f562f0a2d4bcbef";
	target.caller_id = "8dcf46881b922c105f562f0a2d4bcbef";
	target.location = "0ef8a2af1b753c507c7e4046b04bcbeb";
	target.category = "Application";
	target.subcategory = "Internal Application";
	target.business_service = "9a1f8a481b922c105f562f0a2d4bcb77";
	target.u_incident_type = "Incident";
	
	// new code
	
	if(source.u_short_description.indexOf('failed order') > -1){
		target.assignment_group = '25ef250ddb7cbb00fc1e8a3a4896192b'; // give sysId of the group Draw Team
		target.description = current.u_description + "\n \nhttps://testlink";
		
		// add logic to add link
		
	}

	else if(source.u_short_description.indexOf('Incoming call from')> -1){
		target.state = '7'; // give correct choice value for closed
		target.close_notes = 'No action required'; // give correct value here
		target.close_code = 'Closed/Resolved by Caller';// give correct value here
	}
        else
        {
         	target.assignment_group = "0626982cdb4d2410d2178a5039961952";
               // rest of the statements

        }
		
	
	target.x_86994_opsgenie_opsgenie_alert_id = "https://site.app.opsgenie.com/alert/detail/" + source.u_opsgenie_alert_id + "/details";


	if (groupName !== "") {
		var groupEntity = client.queryEntity('sys_user_group', 'name', groupName);

		if (groupEntity !== undefined) {
			target.assignment_group = groupEntity.sys_id.toString();
		} else {
			log.warn("[OpsGenie Web Svc Create] Unable to find group with name \"" + groupName + "\".");
		}
	}
})(source, target, map, log, action==="update");

 

If its helpful, please answer as correct

Regards,
Anshu

View solution in original post

5 REPLIES 5

(function transformRow(source, target, map, log, isUpdate) {
	var client = new OpsGenie_Client();
	var groupName = source.u_assigned_group;
	target.opened_by = "8dcf46881b922c105f562f0a2d4bcbef";
	target.caller_id = "8dcf46881b922c105f562f0a2d4bcbef";
	target.location = "0ef8a2af1b753c507c7e4046b04bcbeb";
	target.category = "Application";
	target.subcategory = "Internal Application";
	target.business_service = "9a1f8a481b922c105f562f0a2d4bcb77";
	target.u_incident_type = "Incident";
	
	// new code
	
	if(source.u_short_description.indexOf('failed order') > -1){
		target.assignment_group = '25ef250ddb7cbb00fc1e8a3a4896192b'; // give sysId of the group Draw Team
		target.description = current.u_description + "\n \nhttps://testlink";
		
		// add logic to add link
		
	}

	else if(source.u_short_description.indexOf('Incoming call from')> -1){
		target.state = '7'; // give correct choice value for closed
		target.close_notes = 'No action required'; // give correct value here
		target.close_code = 'Closed/Resolved by Caller';// give correct value here
	}
        else
        {
         	target.assignment_group = "0626982cdb4d2410d2178a5039961952";
               // rest of the statements

        }
		
	
	target.x_86994_opsgenie_opsgenie_alert_id = "https://site.app.opsgenie.com/alert/detail/" + source.u_opsgenie_alert_id + "/details";


	if (groupName !== "") {
		var groupEntity = client.queryEntity('sys_user_group', 'name', groupName);

		if (groupEntity !== undefined) {
			target.assignment_group = groupEntity.sys_id.toString();
		} else {
			log.warn("[OpsGenie Web Svc Create] Unable to find group with name \"" + groupName + "\".");
		}
	}
})(source, target, map, log, action==="update");

 

If its helpful, please answer as correct

Regards,
Anshu