- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-07-2020 02:26 AM
gs.include('validators');
if (current.getTableName() == "incident" && current.incident_state !='7' && current.incident_state !='6' )
{
//gs.log('Enter');
var str=email.body_text;
current.comments ="reply from: " + email.origemail + "\n\n" + str;
current.update();
}
else if(current.incident_state == '7' || current.incident_state=='6')
{
gs.log('Enter 2');
var callNew = new GlideRecord('new_call');
if( email.origemail.toLowerCase() == 'abc.example.com') {
//if( email.from == 'SNOW.Notifications@client.com') {
//if( email.from == 'abc.example.com'){
//if( email.subject.toLowerCase().indexOf('closed') >= 0 );
gs.log('sh name');
callNew.contact_type = "email";
//GlideSysAttachment.copy('sys_email', sys_email.sys_id, 'incident', incident.sys_id);
//var emailAttachmentObj = new GlideSysAttachment();
//var bytesContent = emailAttachmentObj.getBytes('sys_email', sys_email.sys_id);
//GlideSysAttachment.copy('sys_email', sys_email.sys_id, 'incident');
callNew.caller = current.caller_id;
callNew.short_description = current.short_description; //assuming you want incident short description in call record. else you can have earler statement only
var str=email.body_text;
callNew.description = "**CREATED FROM REPLAY TO Resolved TICKET**\n\nTicket #:" + current.number +"reply from: " + email.origemail + "\n\n" + str;
gs.log('email');
callNew.update();
//callNew.description = "**CREATED FROM REPLAY TO Resolved TICKET**\n\nTicket #:" + current.number + email.body;
gs.log('End');
callNew.insert();
}
}
Hi Developer community,
I am new to servicenow
Can anyone please explain me this script which is used in inbound email action with target table as incident.
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-07-2020 02:42 AM
Hi Deepika,
if (current.getTableName() == "incident" && current.incident_state != '7' && current.incident_state != '6') {
//gs.log('Enter');
var str = email.body_text;
current.comments = "reply from: " + email.origemail + "\n\n" + str;
current.update();
}
This must be a reply inbound action. in the above if part there is a mistake
else if (current.incident_state == '7' || current.incident_state == '6') {
gs.log('Enter 2');
var callNew = new GlideRecord('new_call');
if (email.origemail.toLowerCase() == 'abc.example.com') {
//if( email.from == 'SNOW.Notifications@client.com') {
//if( email.from == 'abc.example.com'){
//if( email.subject.toLowerCase().indexOf('closed') >= 0 );
gs.log('sh name');
callNew.contact_type = "email";
//GlideSysAttachment.copy('sys_email', sys_email.sys_id, 'incident', incident.sys_id);
//var emailAttachmentObj = new GlideSysAttachment();
//var bytesContent = emailAttachmentObj.getBytes('sys_email', sys_email.sys_id);
//GlideSysAttachment.copy('sys_email', sys_email.sys_id, 'incident');
callNew.caller = current.caller_id;
callNew.short_description = current.short_description; //assuming you want incident short description in call record. else you can have earler statement only
var str = email.body_text;
callNew.description = "**CREATED FROM REPLAY TO Resolved TICKET**\n\nTicket #:" + current.number + "reply from: " + email.origemail + "\n\n" + str;
gs.log('email');
callNew.update();
//callNew.description = "**CREATED FROM REPLAY TO Resolved TICKET**\n\nTicket #:" + current.number + email.body;
gs.log('End');
callNew.insert();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-07-2020 02:32 AM
Hi,
whenever email is received to ServiceNow the inbound action would be processed
1) it will check if the table is incident; if incident state is not closed or resolved
a) it would update
Else it would insert new record with the fields populated in new_call table
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-07-2020 02:38 AM
Hello Deepika,
This is a inbound action which will trigger whenever an email is sent to ServiceNow.
Coming to this inbound action, this is a reply mail to an existing record.
1. it basically checking first if the table name is incident and the state of the incident is NOT resolved or closed. If it matches, then it will update the incident with the body of the mail under comments.
2. If it does not match, then it checks if the current incident is resolved or closed. If it matches, then it will create a new incident (becuase the existing incident is resolved/closed).
Hope this clarifies.
Kindly mark the comment as a correct answer and helpful if this answers your question.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-07-2020 02:42 AM
Hi Deepika,
if (current.getTableName() == "incident" && current.incident_state != '7' && current.incident_state != '6') {
//gs.log('Enter');
var str = email.body_text;
current.comments = "reply from: " + email.origemail + "\n\n" + str;
current.update();
}
This must be a reply inbound action. in the above if part there is a mistake
else if (current.incident_state == '7' || current.incident_state == '6') {
gs.log('Enter 2');
var callNew = new GlideRecord('new_call');
if (email.origemail.toLowerCase() == 'abc.example.com') {
//if( email.from == 'SNOW.Notifications@client.com') {
//if( email.from == 'abc.example.com'){
//if( email.subject.toLowerCase().indexOf('closed') >= 0 );
gs.log('sh name');
callNew.contact_type = "email";
//GlideSysAttachment.copy('sys_email', sys_email.sys_id, 'incident', incident.sys_id);
//var emailAttachmentObj = new GlideSysAttachment();
//var bytesContent = emailAttachmentObj.getBytes('sys_email', sys_email.sys_id);
//GlideSysAttachment.copy('sys_email', sys_email.sys_id, 'incident');
callNew.caller = current.caller_id;
callNew.short_description = current.short_description; //assuming you want incident short description in call record. else you can have earler statement only
var str = email.body_text;
callNew.description = "**CREATED FROM REPLAY TO Resolved TICKET**\n\nTicket #:" + current.number + "reply from: " + email.origemail + "\n\n" + str;
gs.log('email');
callNew.update();
//callNew.description = "**CREATED FROM REPLAY TO Resolved TICKET**\n\nTicket #:" + current.number + email.body;
gs.log('End');
callNew.insert();
}