How to user JavaScript String search() Method

Radhika11
Tera Contributor

Hello,

We are receiving service request submitted from using emails.  The RITM description field captures the entire email.

I would like to search the name "From: John,Lopez" in the RITM description field and populate in "Requested For" field.

See attached

 

Could someone please help?   Thank you

matthew_magee1
Giga Guru

This could be tough. What happens if there is another John Lopez or Susan Smith, etc?

Hello @matthew_magee1 

 

You are absolutely correct regarding users with the same name.   

The current process is HR personnel who handles New Hires.  She sent an email to SN. SN creates the Service Request and automatic populate the "Request for" field with the sender name, which is always going to be her name and body of the email goes to the RITM Description field. 

 

Instead of we manually change the "Request For", we would like her to enter the New Hire Name in the body of the email.  We then search for the text that contains for example "New Hire Name:  John, Lopez" and populate it in the Request For field.

 

Any suggestions.

 

Thank you

 

Still sounds risky in the event there are employees w/ the same spelling name.

Is there an employee ID that HR can plug into the email, which would coincide w/ a value on in the user table?

Can you point HR to a portal page (record producer) that they could fill out and choose a specific user, which would then in turn, create the Service Request?

Basheer
Mega Sage

Hi @matthew_magee1 ,

You need to write a before+on insert business rule to achieve it

 

var description = current.description;

if(.description.include("From:")){

var firstLine = description.split('\n')[0];

var split=  firstLine.split(":");

var userName = spllit[1];

var userRecord = new GlideRecord("sys_user");

userRecord.addQuery("name",userName);

userRecord.query();

if(userRecord.next()){

current.requested_for = userRecord.getUniqueValue();

}

 

 

 

}

 

Please hit like button if my suggestion has helped you in any way.
Please mark correct if my response has solved your query.

Cheers,
Mohammed Basheer Ahmed.