Issue with setting values using inbound email action
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-01-2025 08:23 AM
Hi,
I created inbound action to create supplier record. I will be receiving email in below format, and I want to set Stichting Rust Nederland to username string field and AN11217385725 to sap number field of record.How can we achieve this in inbound script?
Email format
This notification contains important information about your SAP Business Network account (ANID: AN01008912882).
Stichting Rust Nederland (AN11217385725) CAN NOW TRANSACT WITH YOU ON SAP Business Network.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-01-2025 10:37 AM
Hi @Karishma Dubey ,
You have to use regex on email body to get the texts you want.
Try this inside your inbound action script.
var body = email.body_text;
// Match the pattern: "Stichting Rust Nederland (AN11217385725)"
var match = body.match(/([\w\s]+)\s+\((AN\d+)\)/);
if (match && match.length === 3) {
var username = match[1].trim(); // Stichting Rust Nederland
var sapNumber = match[2].trim(); // AN11217385725
//do your script on required table
}
Mark this as helpful and correct if this solves your question.
Thanks,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-02-2025 12:27 AM
if the string is different for example "Carolina Soares da Conceição (AN112173857252)" it is not working and it is giving me result like below.
x_itag_myproc: username o
x_itag_myproc: sapNumber AN112173857252
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-02-2025 09:23 AM
The sap number is correct, and name is coming as o because the regular expression is not handling names with special characters likeç or ã . Make sure you include the string check as well.
Ty this updated regex:
var match = body.match(/([\p{L}\s]+)\s+\((AN\d+)\)/u);
Mark this as helpful and correct, if this helps you.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-02-2025 01:44 AM
Hi @Karishma Dubey
To extract the required details from the incoming email, you can use a regular expression to parse the content. Here's an example you can try:
(function runAction(/*GlideRecord*/ current, /*GlideRecord*/ event, /*EmailWrapper*/ email, /*ScopedEmailLogger*/ logger, /*EmailClassifier*/ classifier) {
// Implement email action here
var body = email.body;
var supplierName, sapNumber;
var regex = /(.+?)\s+\((\w+)\)\s+CAN NOW TRANSACT WITH YOU/i;
var match = regex.exec(body);
if (match) {
supplierName = match[1].trim();
sapNumber = match[2].trim();
current.username = supplierName;
current.u_sap_number = sapNumber; // replace with the field name
} else {
gs.error("Failed to parse info from email: " + email.subject);
}
})(current, event, email, logger, classifier);
Regards,
Rohit Singh
