- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-22-2014 03:41 PM
I am trying to do a GlideRecord query on the sys_choice table to, and cant seem to figure this out.
Background
I am receiving email from another system
one of the name:value pairs is "Description"
so what i am trying to do is lookup the 'sys_choice' table to get parse this description and insert as a category option on the u_request form.
Script i have below
if(!email.body.description.nil()){
var des = new GlideRecord('sys_choice');
des.addQuery('label',email.body.description);
des.query(); //Issue the query to the database to get relevant records
if (des.next()){
//Populate Category into request,
req.category = des.sysID;
gs.log("DESCRIPTION>>" + des);
gs.log("EMAIL Description " + email.body.descritpion);
}
}
script log statements returning:
returned is DESCRIPTION>>[object GlideRecord]
EMAIL Description DP / Class not in TQControl
Not quite sure where i am going wrong, any assistance would be greatly appreciated.
Carl
Solved! Go to Solution.
- Labels:
-
Service Mapping

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-22-2014 08:57 PM
In your query I see this line : req.category = des.sysID
Now here if you notice, you are trying to put sysid in a choice field which does not make sense.
Your code could be
req.category = des.label;
OR
req.category = des.value;
Let me know if I misunderstood your question.
Regards,
Bhavesh

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-22-2014 08:57 PM
In your query I see this line : req.category = des.sysID
Now here if you notice, you are trying to put sysid in a choice field which does not make sense.
Your code could be
req.category = des.label;
OR
req.category = des.value;
Let me know if I misunderstood your question.
Regards,
Bhavesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-22-2014 10:00 PM
Thanks
This seemed to resolve the issue and am now populating the category with the correct value.
both the label and the value work as detailed below.
if(!email.body.description.nil()){
var des = new GlideRecord('sys_choice');
des.addQuery('label',email.body.description);
des.query(); //Issue the query to the database to get relevant records
if (des.next()){
//Populate Category into request, and Assignment group into request
req.category = des.value;
gs.log("DESCRIPTION>> " + des.label + " Value " + des.value);
}
}
cheers, great work
Carl

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-22-2014 09:24 PM
Have you tried something like this? I believe you need to take out description from email.body
if(!email.body.nil()){
var des = new GlideRecord('sys_choice');
des.addQuery(email.body, 'CONTAINS', 'label');
des.query(); //Issue the query to the database to get relevant records
if (des.next()){
//Populate Category into request,
// I assume you've defined req somewhere else
req.category = des; // remove sysID here
gs.log("DESCRIPTION>>" + des);
gs.log("EMAIL Description " + email.body.descritpion);
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-22-2014 09:26 PM
You could also get fancy with .indexOf() if you need to parse out certain parts of the email. I haven't tested either of these solutions, but if the above doesn't work I would try matching with .indexOf()