how to call script include into service catalog variable advance reference qualifier

Deepa12
Tera Contributor

Hi,

 

I have written below script include to fetch category values:

var RemoveGPS = Class.create();
RemoveGPS.prototype = {
    initialize: function() {
        
    },
getcategory: function()
{
var category_array = new Array();
 
        var cate = new GlideRecord('sys_choice');
        cate.addQuery('name', 'STARTSWITH', 'incident');
        cate.addQuery('language', '=', 'en');
        cate.addQuery('element', 'STARTSWITH', 'category');
        cate.addQuery('inactive', '=', 'false');
        cate.addQuery('value', 'NOT LIKE', 'GPS%');
        cate.addQuery('value', 'NOT LIKE', 'WFM%');
     cate.query();
 
        while (cate.next()) {
            category_array.push(cate.value.toString());
 
        }
        return category_array;
},
 
    type: 'RemoveGPS'
};
 
THen i called this script include into Service catalog Variable:
Deepa12_0-1695225089258.png

 

In service portal, the category not fetching correctly. it showing all the values. please let me know the corrections.

 

Thanks,

 

1 ACCEPTED SOLUTION

Hi,
This can be done using contain or startswith, what she need is does not start with.



Thanks and Regards,

Saurabh Gupta

View solution in original post

15 REPLIES 15

Hi,

Use below query for the same-

 

name=incident^element=category^inactive=false^language=en^valueSTARTSWITHGPS^valueSTARTSWITHWFM


Thanks and Regards,

Saurabh Gupta

Hi,
You can use below script in your script include-

var RemoveGPS = Class.create();
RemoveGPS.prototype = {
getcategory: function()
{
var category_array = [];
        var cate = new GlideRecord('sys_choice');
        cate.addQuery('name' , 'incident');
        cate.addQuery('language' , 'en');
        cate.addQuery('element', 'category');
        cate.addQuery('inactive', 'false');
     cate.query();
 
        while (cate.next()) {
var ch=cate.getValue('value').toUpperCase();
if(ch.indexOf('GPS')!=0 && ch.indexOf('WFM')!=0)
            category_array.push(cate.getUniqueValue());
        }
if(category_array.length>0)
        return "sys_idIN"+category_array.join(",");
else
    return "sys_idINnothing";
},
 
    type: 'RemoveGPS'
};

Thanks and Regards,

Saurabh Gupta

jonsan09
Giga Sage
Giga Sage

It might just be eaiser to input an encoded query into the reference qualifer, it looks like your script include is just doing filtering.

Deepa12
Tera Contributor

i am unable to filter through encoded reference qualifier - category values is not Startswith GPS.

NOT LIKE operator filter check whole statement - whether category contains GPS values from category.

 

name=incident^element=category^inactive=false^language=en^valueNOT LIKEGPS^valueNOT LIKEWFM 

maroon_byte
Mega Sage

In Surabh's script, if statement should compare with -1 not 0

 

if(ch.indexOf('GPS')!=-1 && ch.indexOf('WFM')!=-1)