How to extract email text from a notification

Chaz_
Tera Guru

Hi,

 

Does anyone know how I can extract just the text from a notification? Currently, we have the English plus the translated text in other languages in the same notification. We are looking to use the Dynamic translations plugin and to do this we need to extract the text and separate out into the 'Translated Notifications' section.

 

Does anyone have any tips on how I can do this?

 

Thanks.

1 ACCEPTED SOLUTION

Thanks for this suggestion. I think in practice, there was no standard pattern in the HTML.

So, I've had to extract into excel and then do a find and replace for <*> with nothing, and replace empty lines using https://www.asap-utilities.com/blog/how-to-delete-blank-lines-in-a-cell-with-multiple-lines-of-text/.

 

View solution in original post

2 REPLIES 2

Harish Bainsla
Kilo Patron
Kilo Patron

In ServiceNow, you can achieve this by leveraging scripting and string manipulation techniques to extract and separate the text from notifications. Here's a general approach you can follow:

  1. Identify the Text Pattern: You need to identify a consistent pattern in your notification messages that separates the English text from the translated text. This could be a specific marker, keyword, or structure that distinguishes the two parts.

  2. Use Scripting: You can use scripting (JavaScript) in ServiceNow to process the notification messages and extract the required text. Typically, this would involve using string manipulation functions.

  3. Custom Script Action: If you're using the Dynamic Translations plugin, you might need to create a custom script action that performs the text extraction and separation. This custom action can be triggered when a notification is received or when a notification record is created or updated.

  4. (function executeRule(current, previous /*, helper*/) {
    // Assuming the notification body has a specific marker like '[TRANSLATED]'
    var notificationBody = current.notification.body;
    var marker = '[TRANSLATED]';

    // Find the marker's position in the notification body
    var markerIndex = notificationBody.indexOf(marker);

    if (markerIndex !== -1) {
    // Extract the English text
    var englishText = notificationBody.substring(0, markerIndex).trim();

    // Extract the translated text
    var translatedText = notificationBody.substring(markerIndex + marker.length).trim();

    // Update the 'Translated Notifications' section
    current.translated_english_text = englishText;
    current.translated_text = translatedText;

    // Save the updated notification record
    current.update();
    }
    })(current, previous);

Thanks for this suggestion. I think in practice, there was no standard pattern in the HTML.

So, I've had to extract into excel and then do a find and replace for <*> with nothing, and replace empty lines using https://www.asap-utilities.com/blog/how-to-delete-blank-lines-in-a-cell-with-multiple-lines-of-text/.