- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-11-2021 05:42 AM
I am trying to update a record's fields in the alm_hardware table from an email with the updated information contained in the email body which includes the associated asset_tag reference. Any ideas on where to start on this? I have seen numerous examples of creating new records but not on updating existing records.
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-11-2021 07:22 AM
Updates are normally only carried out when the email is flagged as reply and the associated record is identified, either via a watermark, or by the record number being present in the subject. It's a little challenging to do this for a "new" email, but not impossible.
First, make sure your inbound email trigger works as expected and your action is triggered by an email using the format you want. Hopefully the formatting of your email is specific enough that you won't have issues with multiple actions being triggered, etc.
In your inbound email action, you'll need to parse out the asset_tag value for the record you want to update and then write a GlideRecord query to lookup that record, set the values based on your email, and then call .update() to update the record.
At the end of the script you will want to call current.setAbortAction(true); which will prevent the system from creating a new record as designed.
Make sure the action has a low execution order and you want to flag it for "stop processing" otherwise you'll likely create an incident from the email as well.
Without all of the details I can't give you an exact example, but something like this would, when triggered, look up an alm_hardware record based on the asset_tag:value passed in the body of the email and then update the comments to be the comments:value passed in the body.
(function runAction( /*GlideRecord*/ current, /*GlideRecord*/ event, /*EmailWrapper*/ email, /*ScopedEmailLogger*/ logger, /*EmailClassifier*/ classifier) {
// Implement email action here
var alm_rec = new GlideRecord('alm_hardware');
alm_rec.addQuery('asset_tag', email.body.asset_tag);
alm_rec.query();
if (alm_rec.next()) {
alm_rec.comments = email.body.comments;
alm_rec.update();
}
current.setAbortAction(true);
})(current, event, email, logger, classifier);
I hope this helps!
If this was helpful or correct, please be kind and remember to click appropriately!
Michael Jones - Proud member of the CloudPires team!
Michael D. Jones
Proud member of the GlideFast Consulting Team!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-11-2021 07:19 AM
Hi Andy,
You can add asset_tag in email subject
1. create new inbound email action which will trigger based on subject contains asset_tag initial letter action type - record action and type - New
2.Need to update old inbound action where you can add subject does not contain aseet_tag inital letter.
You can extract the asset_tag from subject and glide alm_hardware using asset_tag
Ex - I have done same requirement for incident
var str = email.subject;
var number = str.indexOf("INC");
var res = str.substring(number, number + 10);
var bdy = email.body;
var inc = new GlideRecord('incident');
inc.addQuery('number', res);
inc.query();
if (inc.next()) {
inc.comments = email.body_text ;
inc.update();
}
For alm_hardware
var str = email.subject;
var number = str.indexOf("INC");//mention asset tag prefix
var res = str.substring(number, number + 10);
var bdy = email.body;
var almGr= new GlideRecord('alm_hardware');
almGr.addQuery('asset_tag', res);
almGr.query();
if (almGr.next()) {
almGr.comments = email.body_text ;
almGr.update();
}
get asset tag from body
var almGr= new GlideRecord('alm_hardware');
almGr.addQuery('asset_tag', email.body.assettag);
almGr.query();
if (almGr.next()) {
almGr.comments = email.body_text ;
almGr.update();
}
Thanks,
RJ

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-11-2021 07:22 AM
Updates are normally only carried out when the email is flagged as reply and the associated record is identified, either via a watermark, or by the record number being present in the subject. It's a little challenging to do this for a "new" email, but not impossible.
First, make sure your inbound email trigger works as expected and your action is triggered by an email using the format you want. Hopefully the formatting of your email is specific enough that you won't have issues with multiple actions being triggered, etc.
In your inbound email action, you'll need to parse out the asset_tag value for the record you want to update and then write a GlideRecord query to lookup that record, set the values based on your email, and then call .update() to update the record.
At the end of the script you will want to call current.setAbortAction(true); which will prevent the system from creating a new record as designed.
Make sure the action has a low execution order and you want to flag it for "stop processing" otherwise you'll likely create an incident from the email as well.
Without all of the details I can't give you an exact example, but something like this would, when triggered, look up an alm_hardware record based on the asset_tag:value passed in the body of the email and then update the comments to be the comments:value passed in the body.
(function runAction( /*GlideRecord*/ current, /*GlideRecord*/ event, /*EmailWrapper*/ email, /*ScopedEmailLogger*/ logger, /*EmailClassifier*/ classifier) {
// Implement email action here
var alm_rec = new GlideRecord('alm_hardware');
alm_rec.addQuery('asset_tag', email.body.asset_tag);
alm_rec.query();
if (alm_rec.next()) {
alm_rec.comments = email.body.comments;
alm_rec.update();
}
current.setAbortAction(true);
})(current, event, email, logger, classifier);
I hope this helps!
If this was helpful or correct, please be kind and remember to click appropriately!
Michael Jones - Proud member of the CloudPires team!
Michael D. Jones
Proud member of the GlideFast Consulting Team!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-30-2022 03:22 PM
I will name my first born after you. This helped me more than you will ever know. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-11-2021 08:13 AM
Thank you for that, it has set me in the right direction. Note I do get a "InboundActionRef : did not create or update alm_hardware using current message in the email log but it does still update. I am assuming this is because of the setAbortAction line?