The CreatorCon Call for Content is officially open! Get started here.

Transform map script logic

dvelloriy
Kilo Sage

Hello All,

 

Looking for some help on Transform map script logic. We have integration with a monitoring tool and its sending data in one of our staging tables through which incidents are getting created.

 

I need to define the Impact, Urgency and eventually drive priority calculation for target incidents.

below is the snapshot of source staging table:

 

Here I need the drive the logic for Impact calculation through Problem Title.

So if Problem title has ProblemSeverity:AVAILABILITY, then impact should be 2. 

else if Problem title has ProblemSeverity:ERROR then impact should be 3.

there are 4 different severity values.

 

I need to drive the Urgency logic through Tags.

So if Tags has Vitality as V0, then urgency should be 2.

and so on.

 

dvelloriy_0-1729015008688.png

 

Can someone please advise here? I am confused what will work great here: Field map script logic or onbefore script.

Looking for some help.

2 REPLIES 2

sadif_raja
Tera Guru

Hello,

For this scenario, where you need to define logic based on the `Problem Title` and `Tags` in the staging table to determine the **Impact** and **Urgency** fields, it would be best to use a **Transform Map Script** in the **"onBefore" script**. This script can analyze the data before it's transformed, allowing you to perform the calculations before the record is created.

Here's an example approach to implement the logic for both **Impact** and **Urgency**:

 `onBefore` Script:
javascript
(function transformEntry(source, target, map, log, isUpdate) {

// Define the logic for Impact based on the 'Problem Title'
if (source.problem_title.indexOf('ProblemSeverity:AVAILABILITY') !== -1) {
target.impact = 2; // Impact should be 2
} else if (source.problem_title.indexOf('ProblemSeverity:ERROR') !== -1) {
target.impact = 3; // Impact should be 3
} else if (source.problem_title.indexOf('ProblemSeverity:PERFORMANCE') !== -1) {
target.impact = 1; // Assuming Impact should be 1 for performance issues
} else if (source.problem_title.indexOf('ProblemSeverity:SECURITY') !== -1) {
target.impact = 4; // Example for security severity
} else {
target.impact = 5; // Default value or based on your business logic
}

// Define the logic for Urgency based on the 'Tags'
if (source.tags.indexOf('Vitality:V0') !== -1) {
target.urgency = 2; // Urgency should be 2 for Vitality V0
} else if (source.tags.indexOf('Vitality:V1') !== -1) {
target.urgency = 3; // Urgency should be 3 for Vitality V1
} else if (source.tags.indexOf('Vitality:V2') !== -1) {
target.urgency = 4; // Urgency should be 4 for Vitality V2
} else {
target.urgency = 5; // Default Urgency if no match found
}

// Optionally drive the priority calculation based on Impact and Urgency
target.priority = new global.TaskSLAUtils().calculatePriority(target.impact, target.urgency);

})(source, target, map, log, action);
```

### Breakdown:
1. **Impact Logic**:
- The `problem_title` field from the source table is checked for specific keywords like `ProblemSeverity:AVAILABILITY` and `ProblemSeverity:ERROR`.
- Based on the match, the `impact` field in the target incident is assigned the appropriate value.
- You can continue adding more conditions for other severity values.

2. **Urgency Logic**:
- The `tags` field is checked for specific keywords like `Vitality:V0` and `Vitality:V1`, and the `urgency` field is updated accordingly.

3. **Priority Calculation**:
- The `priority` field is automatically calculated based on the combination of **Impact** and **Urgency** using the `calculatePriority()` method from the `TaskSLAUtils` script include.

### Why Use `onBefore` Script?
- **Flexibility**: You can inspect the incoming data before it's transformed, and apply more complex logic if necessary.
- **Performance**: This allows you to modify the target record before it's inserted, reducing the number of update transactions on the system.
- **Priority Calculation**: You can trigger the logic for priority calculation based on the values of Impact and Urgency, which is ideal to handle within this script.

If you require more granularity or specific advice, feel free to share additional details, and I'll assist further!

Best regards,
Raja 

Animesh Das2
Mega Sage
Mega Sage

Hi @dvelloriy ,

 

onbefore transform script can be the best choice here with below logic. You can edit the actual code per your need. Also you don't need to map the 'impact' in the field mapping as it is going to be set via onbefore transform script.

 

(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {
    if(source.problem_title.indexOf('ProblemSeverity:AVAILABILITY') > -1)
        target.impact = 2;
    else if(source.problem_title.indexOf('ProblemSeverity:ERROR') > -1)
        target.impact = 3;
     else if ........................
        target.impact = 4;
    else ................
       target.impact = 5;
})(source, map, log, target);
 
 

If this address your question, please mark this response correct by clicking on Accept as Solution and/or Kudos.

You may mark this helpful as well if it helps you.

Thanks, 

Animesh Das