Add encoded query
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-23-2015 11:43 AM
I have created a CI field that is a list. How can i write an encoded query to change the line that is not working below to an encoded query are both the queries on line 5 and 6 the same? I am trying to match a CI that is in a list.
if (current.u_configuration_item != "") {
var gr = new GlideRecord('u_maint');
//gr.addQuery('u_configuration_item','IN', current.u_configuration_item); This line is not working correctly
gr.addEncodedQuery(u_configuration_item>=current.u_configuration_item); Switch the above query out with an encoded query
gr.addQuery('state', 2);
if (gr.next()) {
current.u_event_state = 3;
current.update();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-09-2024 01:16 AM
The encoded query you have written seems to be incorrect. The operator 'IN' is used to match any one of a list of values, and '>=', which you have used, is a comparison operator. Here's how you can correct it: 1. Comment out or remove the line that is not working correctly. 2. Replace it with the correct encoded query. Here's the corrected code: javascript if (current.u_configuration_item != "") { var gr = new GlideRecord('u_maint'); //gr.addQuery('u_configuration_item','IN', current.u_configuration_item); This line is not working correctly gr.addEncodedQuery('u_configuration_itemIN' + current.u_configuration_item); // Corrected encoded query gr.addQuery('state', 2); if (gr.next()) { current.u_event_state = 3; current.update(); } } In the corrected code: - The encoded query is written as 'u_configuration_itemIN' + current.u_configuration_item. This is equivalent to the commented out addQuery line. - The 'IN' operator is used to match any one of a list of values in the 'u_configuration_item' field. - The 'current.u_configuration_item' is the list of values you are trying to match. Please note that the 'current.u_configuration_item' should be a comma-separated string of values for the 'IN' operator to work correctly. If it's an array, you should convert it to a comma-separated string first.