- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-01-2025 06:05 AM - edited 07-01-2025 06:11 AM
Hello experts,
I need your help to Translate ASCII Code to its corresponding characters once the data is transform to its designated field. As you can see, the code is still reflected.
We have created a business rule to translate it but still not working.
Business rule:
Conditions: current.u_follow_up_communication != null && current.u_follow_up_communication !== ''
I would appreciate any help regarding this matter.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-01-2025 07:00 AM
then why not handle it in the field map or transform script itself
if you are using business rule then please use before update business rule on "sn_hr_core_case_relations" table
1) no need to use GlideRecord again
use this script
(function executeRule(current, previous /*null when async*/) {
var fieldName = 'u_follow_up_communication';
function htmlToPlainText(str) {
if (!str) return '';
// Decode common HTML entities
str = str.replace(/</g, '<')
.replace(/>/g, '>')
.replace(/&/g, '&')
.replace(/"/g, '"')
.replace(/'/g, "'")
// Decimal ASCII entities
.replace(/&#(\d+);/g, function(match, dec) {
return String.fromCharCode(dec);
})
// Hexadecimal ASCII entities
.replace(/&#x([0-9A-Fa-f]+);/g, function(match, hex) {
return String.fromCharCode(parseInt(hex, 16));
});
// Remove HTML tags
str = str.replace(/<\/?[^>]+(>|$)/g, "");
// Clean up whitespace
str = str.replace(/\s+/g, ' ').trim();
return str;
}
var currentValue = current.getValue(fieldName);
if (currentValue) {
var newValue = htmlToPlainText(currentValue);
if (newValue !== currentValue) {
current.setValue(fieldName, newValue);
}
}
})(current, previous);
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-01-2025 06:11 AM
how is the data getting captured in that field?
Are you using some transform map etc?
business rule is on which table?
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-01-2025 06:17 AM
Hi @Ankur Bawiskar ,
Thank you for your response. We are using transform map. The source of the data is from the Integrated software to Servicenow. Once the scheduled job run, it will pull the data and create and update its corresponding servicenow record.
The business rule is configured to sn_hr_core_case_relations.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-01-2025 07:00 AM
then why not handle it in the field map or transform script itself
if you are using business rule then please use before update business rule on "sn_hr_core_case_relations" table
1) no need to use GlideRecord again
use this script
(function executeRule(current, previous /*null when async*/) {
var fieldName = 'u_follow_up_communication';
function htmlToPlainText(str) {
if (!str) return '';
// Decode common HTML entities
str = str.replace(/</g, '<')
.replace(/>/g, '>')
.replace(/&/g, '&')
.replace(/"/g, '"')
.replace(/'/g, "'")
// Decimal ASCII entities
.replace(/&#(\d+);/g, function(match, dec) {
return String.fromCharCode(dec);
})
// Hexadecimal ASCII entities
.replace(/&#x([0-9A-Fa-f]+);/g, function(match, hex) {
return String.fromCharCode(parseInt(hex, 16));
});
// Remove HTML tags
str = str.replace(/<\/?[^>]+(>|$)/g, "");
// Clean up whitespace
str = str.replace(/\s+/g, ' ').trim();
return str;
}
var currentValue = current.getValue(fieldName);
if (currentValue) {
var newValue = htmlToPlainText(currentValue);
if (newValue !== currentValue) {
current.setValue(fieldName, newValue);
}
}
})(current, previous);
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-01-2025 11:26 AM
Hi Ankur,
We followed your advice to handle the conversion in the field mapping script of the Follow-Up Communication field, and it worked. Thanks alot.