- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-30-2023 08:32 AM
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.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-06-2023 02:33 AM
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/.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-30-2023 08:57 AM
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:
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.
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.
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.
(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);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-06-2023 02:33 AM
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/.