How to query limited record and return sys_id's
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-03-2024 07:54 PM - edited 06-04-2024 08:30 AM
Hi All,
How to query to limit. ?
Ex: "case " table has 1001, 1002, 1003, 1004......etc (600 K+ records are there )
"child case" table has only one record with Parent 1003 ,
Checking Child table.Parent value with Parent Table and Retrun the Parent table records details of which are not matched(1001,1002,1004.....etc) with ChildTable.Parent.
we don't want Query Total Parent Table records, From below script first I'm trying with count 10 means if Match not found RETURN that not matched 10-records of sys_id details from Parent table as a output from this Script-Include. .
scriptincludename(). getcase();
getcase :function(){
var querystring = 'active=true^categoryINsoftware,hardware';
var arrayvalues = [];
var arr ='';
arrayvalues = this.filtercases(querystring, arr);
var cases= JSON.stringify(arrayvalues);
return cases;
},
filtercases : function(query1, arr ){
var arrayvalues2 =[];
var count=10;
var query2 = query1;
var childcases = this.childcases().split(',');
if(arr.length!=0){
arrayvalues2.push(arr.split(','));
}
var c1 = new GlideRecord('case');
c1.addEncodedQuery(query1);
c1.setLimit(2);
c1.query();
while(c1.next())
{
if(arrayvalues2.toString().indexOf(c1.getValue('sys_id'))== -1){
arrayvalues2.puch(c1.getValue('sys_id'));
}
arrayvalues2= arrayvalues2.filter(function(ab){
return childcases.indexOf(ab)<0;
});
if(arrayvalues2.length!=count){
this.filtercases(query2, arrayvalues2);
}else{
return arrayvalues2.toString();
}
},
childcases:function(){
var abc =[];
var b1 = new GlideRecord('child case table');
b1.query('active=true');
b1.query();
while(b1.next()){
if(abc.toString().indexOf(b1.getValue('parent'))==-1)
abc.push(b1.getValue('sys_id'));
}
return abc.toString();
},
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-04-2024 03:17 PM
What are the results of your debugging, which functions work correctly and which do not?
in filtercases you set var count=10;
but cl.setLimit(2) means only 2 records will be returned by your query, is this intentional?
There is also a syntax error here
arrayvalues2.puch(c1.getValue('sys_id'));
should be
arrayvalues2.push(c1.getValue('sys_id'));
I would suggest testing in a background window,
working through your code, adding debugging\logging to validate variables, conditional statements and results are as expected for each function.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-10-2024 07:33 PM
I tried with "arrayvalues2.push(c1.getValue('sys_id'));" not working
var arrayvalues2=['CS0001'];
var c1 = new GlideRecord('case');
c1.addEncodedQuery('active=true');
c1.setLimit(2);
c1.query();
while(c1.next())
{
if(arrayvalues2.toString().indexOf(c1.getValue('number'))== -1){
// exclude 'CS0001' remaining any other two values should be pushed // Not happening
arrayvalues2.push(c1.getValue('number'));
}
example : arrayvalues2 = ['CS0001', CS0003', 'CS0002']; new values
Assume childcases = ['CS0001', CS0007', 'CS0009'];
arrayvalues2= arrayvalues2.filter(function(ab){
return childcases.indexOf(ab)<0;
});
var count=10;
Expecting result : arrayvalues2 final result should be [CS0001', CS0003', 'CS0002, CS0007', 'CS0009'];
if( count ==arrayvalues2.length) if array doesn't have 10-values then repeat the cycle till arrayvalues2 get 10 unique values