How to fetch list of records from database table with a query string containing special charachters and spaces?

ranadip1
Kilo Explorer

i have a data base field named as "short_description" in a table customer . I want to fetch list of records from the table with a query string like this;

 

var gr = new GlideRecord('customer');

gr.addQuery('short_description','abc , cfg rth_as@abc.com');

gr.query();

while(gr.next())

{

/* some actions performed */

 

 

}

 

 

-------------------------------------------------

 

the query does not fetch any records from the table customer............... is there any other way to query with that particular string value to fetch data with exact matches?

5 REPLIES 5

geoffcox
Giga Guru

I don't think you can possibly have a string field with that name, precisely because field names can't have special characters and spaces in them. If you try to create a field with a name like that above, SNC will substitute all the spaces and special characters with the underscore, resulting in the field name: "u_abc__efg_ius___poc".


Geoff Cox   please check my post which i have updated above for your reference.


So I went on the demo site and tried the following with no problem. I added a field "u_test_field_gbc" to the change_task table. I put the value "abc, cfg rth_as@abc.com" in the field. Then I wrote the following scheduled job:



do_run_test_script();



function do_run_test_script() {


      var task = new GlideRecord('change_task');


      task.addQuery('u_test_field_gbc','abc , cfg rth_as@abc.com');


      task.query();


      while (task.next()) {


              gs.log('GBC - test query - found task ' + task.getDisplayValue() + ' with test value [' + task.u_test_field_gbc + '].');


      }


}



The system log contained the single entry: GBC - test query - found task CTASK0010001 with test value [abc , cfg rth_as@abc.com].




Is that what you're looking for?




Cheers,


        Geofff.



neetusingh
Giga Guru

I could see that there is some syntax problem. Kindly check whether the table name is "u_customer" instead of "customer".



Second thing, please refer the link for string related query - http://wiki.servicenow.com/index.php?title=Using_GlideRecord_to_Query_Tables#Available_JavaScript_Op...



I hope this helps.