Extract Date from Description and populate Due Date

kevinthury
Tera Guru

We are on week 3 of ServiceNow and I am
looking for a way to extract a date from in Inbound Email and insert this into
the Due Date field of the REQ and RITM records.   I was looking to do so
with an activity within the workflow associated with these inbound email.

How it works...

  1. Email received
  2. Inbound email Action
    created REQ (w/ email subj as Short Desc and body as Desc) and RITM
  3. Workflow Copies Short
    Desc and Desc from REQ to RITM

    4.   Workflow generates
Catalog Task based on contents of RITM Desc

These four steps are in place and
working.   What I would like to do is this create "Step 3.5" that extracts
the Start Date from the RITM Description and plugs that into the RITM

Due Date.

The Start Date in the description is a line
item that looks like this:  

Start Date: 6/23/2017

Since we are very new with ServiceNow, my
scripting skills are poor to non-existent.   Any guidance from this
community will be appreciated.

1 ACCEPTED SOLUTION

Got some javascript help from one of our developers and managed to get this working with the following script.   This script was included as an activity in a Workflow



var string = current.description;


var date = string.indexOf("Start Date: ");   //Mark starting point


var end = string.indexOf("Requestor: ");     //mark End Point


var finaldate = string.substring(date+12,end);




//******************************  


//format date here to yyyy-MM-dd  


//******************************  




var mydate = finaldate;


var chunks = mydate.split('/');


var year = chunks[2].substring(0,4);


var month = chunks[0].substring(0,2);


if(parseInt(month)<10){


    month = '0'+month;


    }


var day = chunks[1].substring(0,2);


var fulldate = year+'-'+month+'-'+day+ " 05:00:00";


var gDate = new GlideDateTime(fulldate);


current.due_date = gDate;


View solution in original post

7 REPLIES 7

Got some javascript help from one of our developers and managed to get this working with the following script.   This script was included as an activity in a Workflow



var string = current.description;


var date = string.indexOf("Start Date: ");   //Mark starting point


var end = string.indexOf("Requestor: ");     //mark End Point


var finaldate = string.substring(date+12,end);




//******************************  


//format date here to yyyy-MM-dd  


//******************************  




var mydate = finaldate;


var chunks = mydate.split('/');


var year = chunks[2].substring(0,4);


var month = chunks[0].substring(0,2);


if(parseInt(month)<10){


    month = '0'+month;


    }


var day = chunks[1].substring(0,2);


var fulldate = year+'-'+month+'-'+day+ " 05:00:00";


var gDate = new GlideDateTime(fulldate);


current.due_date = gDate;


SanjivMeher
Kilo Patron
Kilo Patron

Hi Kevin,



You can get the dates by using below script



var mydate = email.body.start_date;


var gDate = new GlideDate();


gDate.setValue(mydate);





You can find the below thread helpful



Inbound Email Action: Setting Field Values from the Email Body where name has a space



Please mark this response as correct or helpful if it assisted you with your question.

When reading this next question, bear in mind I have no scripting experience.   Any and all scripting in our current configuration was done by consultants prior to turning over to us.   Knowing that...



Where do I place that script you provided?   is it in the Actions tab of the Inbound Email Action or can it be part of a Workflow that is triggered from the email?   Looking at the example you provided, how is the due_date field set with the value from the body of the email?   I guess I would expect to see something like 'current.due_date = gDate' or something like that.