How to store data from email into custom table fields
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-24-2025 07:10 AM
I have a requirement for one use case where am getting mail from different tool
Email sample:
Name: abc
Email: abc@gmail.com
Phone no: 987654320
....etc
Need all these info to be stored in custom table sys_user1 table with fields mapped
I will create a inbound email action, but what script needs to be added to create and store data in that custom table and field mapped ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-24-2025 08:16 PM
Hi @aishwaryajn
You are on the right track by using an Inbound Email Action in ServiceNow. To store the extracted information into your custom table (sys_user1
), you need to write a script that:
- Parses the email body to extract each field's value.
- Maps those values to the appropriate fields in
sys_user1
. - Inserts a new record.
Below is a sample script you can use in the Inbound Email Action (in the "Actions" tab, inside the "Script" field):
// Get the email body as plain text
var body = email.body_text;
// Helper function to extract fields
function extractValue(pattern, body) {
var regex = new RegExp(pattern + "\\s*:\\s*(.*)", "i");
var match = body.match(regex);
return match ? match[1].trim() : "";
}
// Extract values
var name = extractValue("Name", body);
var emailAddress = extractValue("Email", body);
var phone = extractValue("Phone no", body);
// Now create a record in your custom table
var gr = new GlideRecord('sys_user1'); // Use your actual table name
gr.initialize();
gr.u_name = name; // Change u_name to your field name in sys_user1
gr.u_email = emailAddress; // Change u_email accordingly
gr.u_phone_no = phone; // Change u_phone_no accordingly
// Map additional fields as needed here
gr.insert();
Maik