- 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 09:42 PM
I agree with Bhavesh that you would need to put req.category =des.label;
I was looking at your query also and wanted to understand what results you think you would return with your query..
var des = new GlideRecord('sys_choice'); >> So you are going to query sys_choice table - good
des.addQuery('label',email.body.description); >> you want to search for a label that matches email.body.description
des.query(); //Issue the query to the database to get relevant records
Do you think you may need to narrow your search down to the u_request table by adding
des.addQuery('table', 'u_request');
You may be returning some random results - you may also be returning LOTS of results.
try gs.log("Number of records found is: " + des.getRowCount());
Put this before your if statement and it will tell you how many results are returned to you.
Also, have you tried your script in a background script to test your query is correct before using in an inbound action?