Test Inbound Email Action
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-20-2023 07:28 AM - edited 10-20-2023 07:28 AM
Hello All,
- My aim is:
1. To create an incident as soon as Mail XML is received in the 'sys_email' table.
2. To fetch a few details from XML and push it in the incident table.
Below is my script:
(function runAction(/*GlideRecord*/ current, /*GlideRecord*/ event, /*EmailWrapper*/ email, /*ScopedEmailLogger*/ logger, /*EmailClassifier*/ classifier) {
// Log the start of the inbound email action
logger.info("Inbound email action started");
// Get the XML file from the sys_email table
var xmlFile = current.body;
// Log the XML file
logger.info("XML file: " + xmlFile);
// Parse the XML file
var xmlDoc = new XMLDocument(xmlFile);
// Log the XML document
logger.info("XML document: " + xmlDoc);
// Get the Description and Source IP nodes from the XML file
var descriptionNode = xmlDoc.documentElement.selectSingleNode("//Description");
var sourceIPNode = xmlDoc.documentElement.selectSingleNode("//SourceIP");
// Log the Description and Source IP nodes
logger.info("Description node: " + descriptionNode);
logger.info("Source IP node: " + sourceIPNode);
// Create a new incident record
var gr = new GlideRecord("incident");
gr.initialize();
gr.ci_name = sourceIPNode.text;
gr.description = descriptionNode.text;
// Log the incident record
logger.info("Incident record: " + gr);
// Insert the incident record
gr.insert();
// Log the end of the inbound email action
logger.info("Inbound email action ended");
})(current, event, email, logger, classifier);
The task is to put the data of Description node and Source IP node to the incidents 'Description' field and 'CI Name' field.
- Note:
1. I don't have admin access to Production.
2. I only have the XML file from production provided by end user
- Now, when I started testing if the script works or not, I followed the below steps:
1. Imported the XML file into Dev ServiceNow 'sys_email' table. Checked if the logs in the script are printed. But the script didn't run as none logs were printed -- So is it like the script only runs when a new record is created on sys_email table?
2. Tried sending the mail through personal mail ID by copy pasting the XML file in body of mail and sending it to ServiceNow dev instance -- The problem here is I received corrupted XML file in ServiceNow with special characters (&quo). Hence the log showed empty xml body.
--> Is there any mistake in my script ?
--> What can I do to test my script ?