- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-08-2022 03:33 AM
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 -
- If short descriptions contains 'failed order' then assignment group should be 'Draw Team'
- If short description contains 'failed order' add URL link below the existing description.
- 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
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-08-2022 06:55 AM
(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
Anshu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-08-2022 03:37 AM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-08-2022 06:13 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-08-2022 06:25 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-08-2022 06:39 AM
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!