- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-12-2023 08:34 AM
Hi,
We have a requirement whereby after an email is sent a particular string in the body is replaced with the work 'Redacted'. For now i'm trying to get this working in a fix script where I am getting the email body, extracting the string and then replacing it with Redacted. I can see that the value has been updated when I print it but the email body is not getting updated.
var email = new GlideRecord("sys_email");
email.get('aa14f2938746a5108354646e8bbb3592');
var splitBody = email.getValue('body');
var findPassword = splitBody.split('Password is');
var two = findPassword[1];
var trim = two.substring(0,17);
gs.print(trim);
var replace = trim.replace(trim,'Redacted');
gs.print(replace);
email.update();
Output (the below is not a password, just a random string used for testing):
*** Script: dOc04i'XU)18]uJ
*** Script: Redacted
Can anyone assist on how I take the value in replace and use this to overwrite the value in i've taken from email body?
Steven
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-12-2023 08:46 AM
Hi @Steven Watts2 ,
I trust you are doing great.
You can update the email record with the new body value by setting it using the setValue() method before calling the update() method. Here's an updated version of the script that should accomplish your requirement:
var email = new GlideRecord("sys_email");
email.get('aa14f2938746a5108354646e8bbb3592');
var splitBody = email.getValue('body');
var findPassword = splitBody.split('Password is');
var two = findPassword[1];
var trim = two.substring(0,17);
gs.print(trim);
var replace = trim.replace(trim,'Redacted');
gs.print(replace);
email.setValue('body', splitBody.replace(trim, replace)); // set updated body value
email.update();
Please mark the answer correct if it was helpful.
Regards,
Amit Gujarathi
Was this answer helpful?
Please consider marking it correct or helpful.
Your feedback helps us improve!
Thank you!
Regards,
Amit Gujrathi

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-12-2023 08:51 AM
try below script:
var email = new GlideRecord("sys_email");
email.get('aa14f2938746a5108354646e8bbb3592');
var splitBody = email.getValue('body');
var findPassword = splitBody.split('Password is');
var two = findPassword[1];
var trim = two.substring(0,17);
gs.print(trim);
var updatedBody = splitBody.replace(trim,'Redacted');
email.setValue("body",updatedBody);
//gs.print(replace);
email.update();
Thank you,
Ali
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-12-2023 08:46 AM
Hi @Steven Watts2 ,
I trust you are doing great.
You can update the email record with the new body value by setting it using the setValue() method before calling the update() method. Here's an updated version of the script that should accomplish your requirement:
var email = new GlideRecord("sys_email");
email.get('aa14f2938746a5108354646e8bbb3592');
var splitBody = email.getValue('body');
var findPassword = splitBody.split('Password is');
var two = findPassword[1];
var trim = two.substring(0,17);
gs.print(trim);
var replace = trim.replace(trim,'Redacted');
gs.print(replace);
email.setValue('body', splitBody.replace(trim, replace)); // set updated body value
email.update();
Please mark the answer correct if it was helpful.
Regards,
Amit Gujarathi
Was this answer helpful?
Please consider marking it correct or helpful.
Your feedback helps us improve!
Thank you!
Regards,
Amit Gujrathi

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-12-2023 08:51 AM
try below script:
var email = new GlideRecord("sys_email");
email.get('aa14f2938746a5108354646e8bbb3592');
var splitBody = email.getValue('body');
var findPassword = splitBody.split('Password is');
var two = findPassword[1];
var trim = two.substring(0,17);
gs.print(trim);
var updatedBody = splitBody.replace(trim,'Redacted');
email.setValue("body",updatedBody);
//gs.print(replace);
email.update();
Thank you,
Ali
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-12-2023 09:05 AM
Thank you, can't believe I forgot to set the value lol. Both of those solutions worked :).
Thanks again.
Steven