How to pull specific keyword from email subject line

reddy8055
Tera Contributor

Hi,

How can I pull location name (after location: ) from email subject line. whenever email receives using this subject line, I want to pull location and parse to location field (reference field) on catalog item.

 

Email Subject Line: Job Summary Report, location: United States ,Daily -  RNOD-FILE-01

 

var gr = email.subject.toString().split('location: ');
var gr2 = gr[1];
gs.log(" ***Reddy: gr: " + gr);
gs.log(" ***Reddy: gr2: " + gr2);

I am using gr[1] which is pulling job summary report,

Please help!

Thanks,

1 ACCEPTED SOLUTION

Allen Andreas
Administrator
Administrator

Hi,

There's a few ways to do this, but to just keep going with what you have, you can use:

var gr2 = gr[1].split(',')[0];

For this reference field, keep in mind that that field expect a sys_id, so you'd either need to use a GldieRecord and then query to find the sys_id using the name from the parse you did here or...be confident enough to set the display value of that reference field using the name (I'd recommend looking it up instead).

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

View solution in original post

2 REPLIES 2

Allen Andreas
Administrator
Administrator

Hi,

There's a few ways to do this, but to just keep going with what you have, you can use:

var gr2 = gr[1].split(',')[0];

For this reference field, keep in mind that that field expect a sys_id, so you'd either need to use a GldieRecord and then query to find the sys_id using the name from the parse you did here or...be confident enough to set the display value of that reference field using the name (I'd recommend looking it up instead).

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

Jaspal Singh
Mega Patron
Mega Patron

If the format will always be the same you can try below.

var gr = 'Job Summary Report, location: United States ,Daily -  RNOD-FILE-01';
var gr2 = gr.split('location:')[1]; //gets text after location:
var gr3=gr2.split(',')[0]; //gets text before ,Daily
gs.print(" ***Reddy: gr: " + gr);
gs.print(" ***Reddy: gr2: " + gr2);
gs.print(" ***Reddy: gr2: " + gr3);