Help with GlideRecord query

carlos_monchuch
Giga Contributor

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

1 ACCEPTED SOLUTION

Bhavesh Jain1
Giga Guru

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


IGate-logo.png


http://www.igate.com


View solution in original post

5 REPLIES 5

Bhavesh Jain1
Giga Guru

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


IGate-logo.png


http://www.igate.com


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


kopp820
Mega Guru

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);


           


              }


      }


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()