- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-20-2017 09:56 PM
I've created an advanced User criteria to display a set of cat items only to users who have a certain CONTRACT in their assignment groups. This is my script:
Am I missing something here ? (I tried logging, script executing till the final GlideAggregate 'if' condition)
getFliContract();
function getFliContract() {
var array = [];
answer = false;
var usr = gs.getUser();
var contract = new GlideRecord('u_contract');
contract.addQuery('u_name','Flights);
contract.query();
if (contract.next()) {
var cont_sysid = contract.getValue('sys_id');
var group = new GlideRecord('sys_user_group');
group.addQuery('u_contract',cont_sysid);
group.query();
while(group.next()){
array.push('' +group.sys_id);
}
}
for(var i=0;i<array.length;i++) {
var user = new GlideAggregate('sys_user_grmember');
user.addQuery('user',usr);
user.addQuery('group',array[i]);
user.addAggregate('COUNT');
user.query();
if(user.Next()) {
if(user.getAggregate('COUNT') > 0) {
answer = true;
}else {
answer = false;
}
}
}
return answer;
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-21-2017 03:29 AM
Hi again,
Could you try to hardcode some sys_id's into the variables and then see if it changes anything ? -just to test
If i do this in a fix script in my dev instance as user (sys admin) it works.
answer = (function(){
var usr = gs.getUserID(); //sys admin
var grp = '287ee6fea9fe198100ada7950d0b1b73,cfcbad03d711110050f5edcb9e61038q'; //1 of these groups admin is a member of
gs.print('usr ' + usr);
var user = new GlideRecord('sys_user_grmember');
user.addQuery('user',usr);
user.addQuery('group','IN',grp);
//user.addAggregate('COUNT');
user.query();
var count = 0;
//if(user.next()) {
count = user.getRowCount();
gs.log('count is' +count); //count is 1
if(count > 0) {
gs.log('iteration 5');
return true;
}
})();
gs.log(answer); //returns tru
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-21-2017 01:28 AM
And
user.addQuery('group','in',array.toString());
should be
user.addQuery('group','IN',array.toString());
Sorry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-21-2017 01:55 AM
Nah mate...still ain't working!!
On Wed, Jun 21, 2017 at 6:29 PM, simonchristensen <
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-21-2017 02:52 AM
Did u try this ?
var usr = gs.getUserID();
and
user.addQuery('user',usr);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-21-2017 03:09 AM
Yep, tried this one as well... Nothing seems working... Have tried
everything discussed on this thread, still nothing...
On 21 Jun 2017 7:53 PM, "simonchristensen" <
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-21-2017 03:29 AM
Hi again,
Could you try to hardcode some sys_id's into the variables and then see if it changes anything ? -just to test
If i do this in a fix script in my dev instance as user (sys admin) it works.
answer = (function(){
var usr = gs.getUserID(); //sys admin
var grp = '287ee6fea9fe198100ada7950d0b1b73,cfcbad03d711110050f5edcb9e61038q'; //1 of these groups admin is a member of
gs.print('usr ' + usr);
var user = new GlideRecord('sys_user_grmember');
user.addQuery('user',usr);
user.addQuery('group','IN',grp);
//user.addAggregate('COUNT');
user.query();
var count = 0;
//if(user.next()) {
count = user.getRowCount();
gs.log('count is' +count); //count is 1
if(count > 0) {
gs.log('iteration 5');
return true;
}
})();
gs.log(answer); //returns tru
}