How to match a number from subject line of email to a field on target table in inbound action?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-12-2022 01:33 AM
I need to match a number in subject line (which is at the end of subject) to a field in target table.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-12-2022 01:57 AM
Hi apoorva,
You could give us a lot more information, then it would be easier to help you.
But let's say it is an incident number you need, and then need to apply that to a field in a target table, you could do something in the line of:
var subjectString= email.subject.toString();
var incident_number = /INC[0-9]{7}/g; //INC0161741 - If not an incident remove INC and adjust the number inside {} to the number you expect.
var found_inc = subjectString.match(incident_number);
if(found_inc) {
current.field_name = found_inc;
}
Best regards,
Sebastian Laursen
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-16-2022 06:18 AM
Hello. I will be receiving mail to my inbox with subject which will contain a unique number CW433 (var contract_number) . i have to match this number with a field (contract_reference_number) in my target table and update that record. i am able to extract the unique number from my subject but not able to match . this is my code
var subject = email.subject.toString();
var subjectsplit1 = subject.split('(');
var subjectsplit2 = subjectsplit1[1];
var subjectsplit3 = subjectsplit2.split(')');
var contract_number = subjectsplit3[0];
gs.info("outputValue6: " + contract_number);
var contract_ref = new GlideRecord('procurement_request');
contract_ref.addQuery('contract_reference_number', contract_number);
contract_ref.query();
if (contract_ref.next()) {
{
contract_ref.state = 105;
contract_ref.comments = contract_number;
contract_ref.update();
//current.state = 105;
// current.update();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2022 05:54 AM
Sebastian,
Your code above was very helpful. This is what I ended up using. One modification I had to make was to add a [0] at the end of your last line, otherwise it inserted a javascript error into the field.
gs.include('validators');
//Example Subject: Escalating Case # 2282-20174 to Service Desk
var subjectString= email.subject.toString();
var bb_number = /[0-9]{4}-[0-9]{5}/g; //Gets Escalation number ex Case # 2282-20174
var found_number = subjectString.match(bb_number);
if(found_number) {
current.u_reference_number = found_number[0]; // use the 1st array element
}
current.insert();