- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-07-2023 03:16 AM - edited 11-07-2023 03:21 AM
Hello Community
I am trying to create an automated standard change record using inbound email content via Flow Designer.
1- I set my trigger as Inbound email and also set the relevant conditions.
2- For the action part, I selected Create Record (Create Change Request Record)
3- I filled in the fields (type, category, description, assignment group, close notes etc.)
Even though filling out those fields was pretty straight forward, I have an issue with "actual start date " field. I wanted to take it from email, not to pick a date using the calendar icon. Therefore I created a custom action in flow designer and called it "Parse Date from email". I will also share the script which seems to be working fine.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-07-2023 05:01 AM - edited 11-07-2023 05:07 AM
Hi @AysenurU
You can convert this to GlideDateTime object, try the following script in your script step. Also change the output variable type to Date/Time (both script step and action outputs).
(function execute(inputs, outputs) {
const emailContent = inputs.emailBody;
const dateRegex = /Started at (.* UTC)/;
const dateMatch = emailContent.match(dateRegex);
if (dateMatch && dateMatch[1]) {
const actualStartDate = dateMatch[1];
var simpleDateFormat = 'E, dd MMM yyyy HH:mm:ss z';
var gdt = new GlideDateTime();
gdt.setDisplayValue(actualStartDate,simpleDateFormat);
outputs.actual_start_date = gdt;
} else {
throw new Error("Actual Start Date not found in email content.");
}
})(inputs, outputs);
Please mark my answer helpful and accept as solution if it helped 👍✔️
Anvesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-07-2023 06:17 PM
@AysenurU Sure, create another output variable at script step and outputs as planned_end_date of Date/Time type and try the below code in same action,
(function execute(inputs, outputs) {
const emailContent = inputs.emailBody;
const dateRegex = /Started at (.* UTC)/;
const dateMatch = emailContent.match(dateRegex);
if (dateMatch && dateMatch[1]) {
const actualStartDate = dateMatch[1];
var simpleDateFormat = 'E, dd MMM yyyy HH:mm:ss z';
var startGdt = new GlideDateTime();
startGdt.setDisplayValue(actualStartDate,simpleDateFormat);
var endGdt = new GlideDateTime();
endGdt.setDisplayValue(actualStartDate,simpleDateFormat);
endGdt.addDaysUTC(3);
outputs.actual_start_date = startGdt;
outputs.planned_end_date = endGdt;
} else {
throw new Error("Actual Start Date not found in email content.");
}
})(inputs, outputs);
Please mark my answer helpful and accept as solution if it helped 👍✔️
Anvesh

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-07-2023 04:41 AM
Hi @AysenurU
Using a background script I can convert this to a GlideDateTime object.
You can use this in your script:
var dt = 'Thu, 02 Nov 2023 08:26:53 UTC';
var dtObj = new GlideDateTime();
dtObj.setDisplayValue(dt, "E, d MMM yyyy HH:mm:ss z");
gs.info(dtObj.getDisplayValue());
Help others to find a correct solution by marking the appropriate response as accepted solution and helpful.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-07-2023 04:54 AM
you can use script shared by Peter and enhance your script
check this blog for more details on GlideDateTime formats
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-07-2023 05:01 AM - edited 11-07-2023 05:07 AM
Hi @AysenurU
You can convert this to GlideDateTime object, try the following script in your script step. Also change the output variable type to Date/Time (both script step and action outputs).
(function execute(inputs, outputs) {
const emailContent = inputs.emailBody;
const dateRegex = /Started at (.* UTC)/;
const dateMatch = emailContent.match(dateRegex);
if (dateMatch && dateMatch[1]) {
const actualStartDate = dateMatch[1];
var simpleDateFormat = 'E, dd MMM yyyy HH:mm:ss z';
var gdt = new GlideDateTime();
gdt.setDisplayValue(actualStartDate,simpleDateFormat);
outputs.actual_start_date = gdt;
} else {
throw new Error("Actual Start Date not found in email content.");
}
})(inputs, outputs);
Please mark my answer helpful and accept as solution if it helped 👍✔️
Anvesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-07-2023 08:37 AM