Inbound Email actions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
a month ago
Hello team,
I had a requirement for the inbound email action -
When some user sends and email with the subject that starts with {Asset Reutilization} and in body { Asset serial number - 123 , Asset location - xyz , Asset centre number - 123 , Asset state - Instock }
Based on this body asper the details given we need to chnage the state of assest as requested in email and also the location based on centre number .
For this i got a script;
Name - Asset Reutilization Update
Type - New
Condition - email.subject && email.subject.toLowerCase().indexOf("asset reutilization") > -1
Script -
- Labels:
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
a month ago
Can you try below script
(function process(inboundAction, email, event, logger) {
var body = email.body_text || email.body; // Fallback if body_text is empty
logger.log("Email body:\n" + body);
var serial = "";
var state = "";
var centreNum = "";
// More flexible regex matching
var serialMatch = body.match(/asset serial(?: number)?\s*[-:]\s*([^\n\r,]+)/i);
var stateMatch = body.match(/asset state\s*[-:]\s*([^\n\r,]+)/i);
var centreMatch = body.match(/centre number\s*[-:]\s*([^\n\r,]+)/i);
if (serialMatch) serial = serialMatch[1].trim();
if (stateMatch) state = stateMatch[1].trim();
if (centreMatch) centreNum = centreMatch[1].trim();
logger.log("Extracted values - Serial: " + serial + ", State: " + state + ", Centre Number: " + centreNum);
if (!serial) {
logger.log("No asset serial found in email body");
return;
}
var assetGR = new GlideRecord("alm_hardware");
assetGR.addQuery("serial_number", serial);
assetGR.query();
if (assetGR.next()) {
logger.log("Asset found: " + assetGR.getDisplayValue());
// Install status mapping
var stateMap = {
"instock": "6",
"in stock": "6",
"retired": "7",
"in use": "1",
"pending": "2"
// Add more if needed
};
var normalizedState = state.toLowerCase();
if (stateMap[normalizedState]) {
assetGR.install_status = stateMap[normalizedState];
logger.log("Install status updated to: " + stateMap[normalizedState]);
} else {
logger.log("No valid install status mapping for: " + state);
}
// Location update
if (centreNum) {
var locGR = new GlideRecord("cmn_location");
locGR.addQuery("u_centre_number", centreNum);
locGR.query();
if (locGR.next()) {
assetGR.location = locGR.sys_id;
logger.log("Location updated to: " + locGR.getDisplayValue());
} else {
logger.log("No location found for centre number: " + centreNum);
}
}
assetGR.update();
logger.log("Asset record updated successfully.");
} else {
logger.log("No asset found with serial number: " + serial);
}
})(inboundAction, email, event, logger);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 weeks ago
Still this did not change the values for the selected location