How to trim data from received email's body?

Rahul J
Mega Expert

G'day all,

I've a requirement such that as soon as an email will be received an Inbound Email Action Script should run, which will fetch the incident number from the body of that email and put it into a custom field  created on Incident table.

The email received is like this:

find_real_file.png

 

The incident number highlighted in Yellow should be trimmed from the email body and should be placed in a custom field - u_new_incident field on Incident Table.

Can some do me a massive favor by providing script that can be used to achieve this requirement.

Cheers-

Rahul J.

 

 

1 ACCEPTED SOLUTION

Rahul J
Mega Expert

Finally, I found a solution to this requirement.

I created an Inbound Email Action like this:

(function runAction(/*GlideRecord*/ current, /*GlideRecord*/ event, /*EmailWrapper*/ email, /*ScopedEmailLogger*/ logger, /*EmailClassifier*/ classifier) {

// Implement email action here
var rSubject=email.subject;
var bod=email.body_text;
var bod1=bod.toString();
var rBody=bod1.substring(0,12);


var inc1= new GlideRecord('incident');
inc1.addQuery('number',rSubject);
inc1.query();

gs.print("rows"+ inc1.getRowCount());

if (inc1.next()){
inc1.u_new_incident=rBody;
inc1.update();

}

})(current, event, email, logger, classifier);

 

And, everything worked smoothly. A big shoutout to community members who helped me in achieving this.

Cheers-

Rahul J.

View solution in original post

9 REPLIES 9

AbhishekGardade
Giga Sage

Hello rahul,

can you send me a sample email body format? So I can help you to trim data. I have implemented a same functionality in my project.

Thanks,

Abhishek

Thank you,
Abhishek Gardade

Hi Abhishek,

Sorry for the late reply

My subject line just include an Incident number: INC0021977

and my requirement is put this incident number onto a custom created field on Incident table.

The custom created field : u_new_incident

For this purpose I have created an Inbound Email Actions as:

(function runAction(/*GlideRecord*/ current, /*GlideRecord*/ event, /*EmailWrapper*/ email, /*ScopedEmailLogger*/ logger, /*EmailClassifier*/ classifier) {

// Implement email action here

current.u_new_incident = email.subject;

})(current, event, email, logger, classifier);

as suggested by @Manish in this thread.

Would really appreciated ya help.

Thanks,

Rahul J.

G'day Abhishek,

Sorry for the late response.

So, email body is like this:

<html><head></head><body><p>&nbsp;This incident number is coming from target instance: RXINC0017129</p><div>&nbsp;</div><div style="display:inline">Ref:MSG0021431_weKJ2DjFaVkJwE5SiVgs</div></body></html>

From the aforementioned body of email I want to trim the portion highlighted in yellow onto a custom field called: u_new_incident (this field is present in Incident table).

Cheers-

Rahul J.

 

Ashvini Kadus1
Kilo Guru

Hi Rahul,

 

Please refer below link:

Pull information from email body for inbound action

 

It will help you.

Kindly mark correct or helpful if it helps you to solve your query.

 

Thank You,

Ashvini k 

 

Rahul J
Mega Expert

Finally, I found a solution to this requirement.

I created an Inbound Email Action like this:

(function runAction(/*GlideRecord*/ current, /*GlideRecord*/ event, /*EmailWrapper*/ email, /*ScopedEmailLogger*/ logger, /*EmailClassifier*/ classifier) {

// Implement email action here
var rSubject=email.subject;
var bod=email.body_text;
var bod1=bod.toString();
var rBody=bod1.substring(0,12);


var inc1= new GlideRecord('incident');
inc1.addQuery('number',rSubject);
inc1.query();

gs.print("rows"+ inc1.getRowCount());

if (inc1.next()){
inc1.u_new_incident=rBody;
inc1.update();

}

})(current, event, email, logger, classifier);

 

And, everything worked smoothly. A big shoutout to community members who helped me in achieving this.

Cheers-

Rahul J.