Ahmmed Ali
Giga Sage

Hello @matthew_magee1 

 

Is the script include client callable? the script include should be client callable in order to be used in condition.

 

Thanks,

Ali

matthew_magee1
Giga Guru

Yes sir, client callable is checked

One more check, may be just a type, new keyword is missing.

 

Sys ID IS ONE OF javascript: new scriptInclude().function().

 

Also did you check using the script include in normal list view of catalog item table. If the script include is not working in list view as well then some issue with script include only. If it is working there and not in catalog builder then some configuration/limitation there.

 

Thank you,

Ali

I ended up creating an on-before query business rule that checks the associated template/Available for/Groups and if the user is part of that group, add the catalog item in an array and then put that cat item in the query to filter the results. Works like a champ. For anyone who may want to do something similar, here is my business rule code:

 

Table: sc_cat_item

Advanced: true

When: Before/Query

Script:

(function executeRule....) {

if(gs.getSession().isInteractive() && !gs.hasRole('admin')){
var user =gs.getUserID();
var cat_items = [];
getCatItems;
var q=current.addQuery('sys_id','IN',cat_items);
}

fucntion getCatItems() {
var gr = new GlideRecord('sc_cat_item');
gr.addEncodedQuery('sc_template!=NULL^sys_class_name=sc_cat_item');
gr.query();
while(gr.next()){
var template = gr.sc_template;
var item = gr.sys_id.toString();
getAvailableFor(template,item);
}

function getAvailableFor(template,item) {
var gr = new GlideRecord('sc_template');
gr.addQuery('sys_id',template);
gr.query();
while(gr.next())
var availableFor = gr.available_for;
parseUserCriteria(availableFor, item);
}
}

function parseUserCriteria(availableFor, item){
if(availableFor.includes(',')){
availableFor = availableFor.split(',');
for (var a in availableFor) {
var uc = availableFor[a];
getUserCriteriaInfo(availableFor[a], item);
}
} else {
getUserCriteria(availableFor, item);
}

function getUserCriteriaInfo(uc_sys_id,item) {
var gr = new GlideRecord('user_criteria');
gr.get(uc_sys_id);
var user = gr.getValue('user');
var groups = gr.getValue('group');
var roles = gr.getValue('role');
var company = gr.getValue('company');
var location = gr.getValue('location');
var department = gr.getValue('department');
if(users) {
checkUsers(users,item);
}
if(groups){
checkGroups(groups,item);
}
if(company){
checkCompany(company,item);
}
if(location) {
checkLocation(location, item);
}
if(department) {
checkDepartment(departement, item);
}
}

function checkUsers(users,item) {
if(users.includes(user)) {
doSomething();
}
}

function checkGroups(groups,item) {
var gr = new GlideRecord('sys_user_grmember');
gr.addQuery('group.sys_id','IN',groups);
gr.addQuery('user',user);
gr.query();
if(gr.hasNext()){
cat_items.push(item);
}
}

function checkRoles(roles,item) { }

function checkCompany(company,item) { }

function checkLocation(location,item) { }

function checkDepartment(department,item) { }

}

 

FYI: There may be some typos in the above code.

 

I tried to use getMyGroups() function and get the groups from the user criteria by dot-walking but it didn't work too well. Oh well. 

Hi Matthew,

Any luck with your requirement? How you achieved?