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

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

I hope you are having short description in your import set as field

(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";

	if(source.u_short_description.indexOf('failed order') > -1){
		target.assignment_group = ''; // give sysId of the group Draw Team
		
		// add logic to add link
		
	}

	if(source.u_short_description.indexOf('incoming call')> -1){
		target.state = '4'; // give correct choice value for closed
		target.close_notes = ''; // give correct value here
		target.close_code = '';// give correct value here
	}

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

});

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Community Alums
Not applicable

Hi Ankur,

Thanks so much!

All of this is now working except -

If short descriptions contains 'failed order' then assignment group should be 'Draw Team'

It still assigns this to the team which is stated in line -

target.assignment_group = "0626982cdb4d2410d2178a5039961952";

 

Here is the full code -

(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
		
	}

	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
	}

	
	// new code
	
	
	target.assignment_group = "0626982cdb4d2410d2178a5039961952";
	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");

 

The code at the bottom is out of the box and could be effecting this?

Thanks again,
Alex

You are using target.assignment_group 2 times

so after if condition , it again assign back to 0626982cdb4d2410d2178a5039961952

find_real_file.png

Regards,
Anshu

Community Alums
Not applicable

Thanks for the reply.

How to I stop this?

So keep the if statement to assign to group 1, but if it doesnt match assign to group 2.

Currently its always being assigned to group 2.

Thanks!