- 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 08:26 AM
Correct, the system is detecting that you didn't modify or insert the record from current, which for a new email is a new record.
This isn't...exactly...an intended use case; at least not a documented one, but it does get the job done.
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!