Querying glide_list to match values

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-24-2008 10:24 AM
Dear SNC Heroes,
Please tell if there is an easy way to query "glide_list" (i.e. Watch List, for instance) values in the database. The glide list value for watch_list is a comma-delimited list of sys_id values (example: "543254254fds56453,5423543fdsf453254fd,5435425gfdasgf").
(1) Is this stored in the db as a single value? For instance, the following does not appear to yield matches when the Watch Lists (db vs. current) are composed in different orders:
var glQuery = new GlideRecord ("incident");
glQuery.addQuery ("watch_list", current.watch_list);
glQuery.query ();
(2) Is there a simple way to do this query to find matching Glide List combinations? Simple means without doing JS string splitting, matching, pre or post query. 🙂
Help is really appreciated.
Thanks,
IngyHere
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-24-2008 01:47 PM
Not sure if there's a shortcut but here's a work-around I've used on other lists. The only gap is that you will also get results for watch lists that contain extra items, but you could process those post-query by sorting each array and compare. I've also used these custom array methods a number of time in the past for working with multiple arrays.
Split the current list to get an array. For each item in the list add a query of 'watch_list','CONTAINS',array[Element]
So you are basically querying where watch list contains all of the current list items.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-25-2008 06:32 AM
Hello Guys,
I did have the same problem here and I created a business rules to help me out on it, the code I used is that (sorry, but there are some Portuguese words on my script):
function myRefListaContrato()
{
if (!has_current)
{
return;
}
else{
var tipo = current.parent.sys_class_name;
var pai = current.u_parent;
var array = '';
var list = '';
var retorno = '';
var listpac = '';
var arraypac = '';
var aux = '';
var aux2 = '';
var nomePort = '';
var contrato = new GlideRecord('ast_contract');
contrato.addQuery('sys_id', pai);
contrato.query();
while(contrato.next())
{
list = contrato.u_portifolio_servicos.toString();
array = list.split(",");
for (var i=0; i < array.length; i++) {
aux = array;
var portifolio = new GlideRecord('u_portifolio_de_servicos');
portifolio.addQuery('sys_id', '=', aux);
portifolio.query();
while(portifolio.next()){
nomePort = portifolio.u_nome_do_servico;
var pacote = new GlideRecord('u_pacotes_de_servicos');
pacote.query();
while(pacote.next())
{
listpacote = pacote.u_portfolio_de_servico.toString();
arraypacote = listpacote.split(",");
for (var j=0; j < arraypacote.length; j++) {
aux2 = arraypacote[j];
if(aux2 == aux)
{
retorno += (',' + pacote.sys_id);
}
}
}
}
}
}
}
if(retorno == "")
{
gs.addInfoMessage("Não existem pacotes associdos ao portifólio selecionado no contrato");
}
return 'sys_idIN' + retorno;
}