Question on inbound action creating request
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-03-2024 11:42 PM
Hi All,
I have one requirement on creating request via inbound action, here i have written inbound action sc_request table to create a request, please find the below code which i have written:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-04-2024 01:21 AM
Hi @Mani60 ,
To fetch item variables from the email body and dynamically create a request in ServiceNow using an inbound action, you can follow these steps:
- Parse the email body to extract the item variables.
- Use the extracted variables to populate the request item in the cart.
- Create the request using the populated cart.
Here's an updated version of your script that includes parsing the email body to extract item variables:
// Parse the email body to extract item variables
var emailBody = current.body_text; // Assuming 'current' is the GlideRecord representing the email record
var contractorName = ''; // Initialize variables
var manager = '';
var requestDescription = '';
// Use regular expressions or other parsing methods to extract item variables from the email body
// Example regular expression to extract contractor name
var contractorNameRegex = /Contractor Name: (.*)/i;
var contractorNameMatch = emailBody.match(contractorNameRegex);
if (contractorNameMatch) {
contractorName = contractorNameMatch[1];
}
// Similar parsing for other variables like manager and request description
// Create the request item in the cart
var cartId = GlideGuid.generate(null);
var cart = new Cart(cartId);
var item = cart.addItem('030bfcd11b3f6050772853de034bcbb5'); // Assuming this is the item ID
cart.setVariable(item, 'contractor_name', contractorName);
cart.setVariable(item, 'manager', manager);
cart.setVariable(item, 'request_description', requestDescription);
// Place the order and create the request
var rc = cart.placeOrder();
gs.info('Request created: ' + rc.number);
Replace 'current.body_text'
with the appropriate field containing the email body in your environment. Adjust the regular expressions and parsing logic to match the format of the email body where the item variables are specified.
This script assumes that the email body contains specific markers or patterns for each item variable (e.g., "Contractor Name: John Doe"). Adjust the regular expressions and parsing logic as needed based on the actual format of your email body.
Thanks,
Ratnakar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-04-2024 05:01 AM
Hi@Ratnakar7 Thanks For Reply
I have try this code but item variable value showing empty.
Please find below snapshot.
Could you please help me on where i can make mistake.
Thanks,