- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-03-2020 11:09 AM
So, what I'm doing is extracting bits of an email to fill various fields for creating an incident from an inbound email. The case here is that someone submits a ticket to helpdesk for someone that called them.
I'm able to set the description and classification using the below code, but any field that is a reference type seems to fail. My question is, whats the trick to assigning data to a reference field? I'm testing this with valid data that exist for the fields, so its not that wacky inputs are being rejected. I also know I'm extracting the text I want(tested it in a shell). So my issue is with setting fields like current.location, current.assigned_to, and current.assignment_group.
Sorry if I'm not very clear about this, I'm new to servicenow & still trying to wrap my head around its nuances.
//Extracts a substring between two parts of a string
function extractData(data, startStr, endStr)
{
subStrStart = data.indexOf(startStr) + startStr.length;
return (data.substring(subStrStart,subStrStart + data.substring(subStrStart).indexOf(endStr))).trim();
}
if((email.origemail).includes("tpcgrp.com"))
{
current.location = extractData(finalDescription,"Location:", "Assign To:");
current.assignment_group = extractData(finalDescription,"Assignment Group:", "Assign");
current.assigned_to = extractData(finalDescription,"Assigned To:", "Classification:");
current.u_classification = extractData(finalDescription,"Classification:","Message:");
current.description= finalDescription.substring(finalDescription.indexOf("Message:"));
}
finalDescription is just the body of the email after a boilerplate warning is truncated from the end.
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-03-2020 11:13 AM
Hi there,
The value you are setting in the reference field, is now a string. So do a GlideRecord query, to look up that string, and retrieve the sys_id. Then simply pass the sys_id to the reference.
If my answer helped you in any way, please then mark it as helpful.
Kind regards,
Mark
---
LinkedIn
Community article list
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-05-2020 01:07 AM
Oke, indeed the table like I mentioned 🙂
Small tips on your script:
What if you have users with the same name. Do you have error handling or something for that? Now you are only performing a query + if, so the first user found.
glide3.getValue("sys_id")
-> You can use glide3.getUniqueValue() here, same for glide4.getValue("sys_id");
glide3, glide4
-> Rename these into more self-descriptive names. You just set up this code, so now you know what's it all about. Though if you look at this code half year later, or someone else has to proceed with your code, it's hard to immediately understand what glide3, glide4, etc is.
Do you still need help on this, or is your issue resolved with this?
If my answer helped you in any way, please then mark it as helpful.
Kind regards,
Mark
---
LinkedIn
Community article list
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field