Advanced user criteria for potal business
						
					
					
				
			
		
	
			
	
	
	
	
	
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-04-2025 09:34 AM
I need to create a user criteria that meets the following criteria: The Contract table is ast_contract, the Contact table is customer_contact, and the Account table is customer_account. This should be an advanced user criteria with a script to check the current contact in the portal, considering the contacts in the Contact tab of the customer_account table, query all ACTIVE contracts for the account they are part of, and then query, depending on whether they are AMS criteria, the sys_id of the contract model found in the sn_b2b_portal.glide.sc.portal.ams_contract_models property. If the glidequery contains next, that is, there is at least one record, return true; otherwise, return false.
I created this code, but it's not working. Could someone please help me?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-04-2025 09:41 AM
Hi @mariasilva ,
Good day !!
Try out this code and try checking or validate that sn_b2b_portal.glide.sc.portal.ams_contract_models property exists and holds only valid sys_ids..
(function () {
  
  var userSID = gs.getUserID();
  var accounts = new GlideQuery('customer_contact')
    .where('user', userSID)
    .where('active', true)
    .select('account')
    .toArray();
  if (!accounts.length)
    return false; 
  var propVal = gs.getProperty('sn_b2b_portal.glide.sc.portal.ams_contract_models') || '';
  var models = propVal.split(',')
    .map(function (s) { return s.trim(); })
    .filter(function (s) { return s && s.length === 32; });
  if (!models.length)
    return false; 
  // For each associated account
  for (var ai = 0; ai < accounts.length; ai++) {
    var acctId = accounts[ai].account;
    var c = new GlideQuery('ast_contract')
      .where('account', acctId)
      .where('active', true)
      .where('contract_model', 'IN', models)
      .select('sys_id')
      .next();
    if (c)
      return true; 
  }
  return false;
})();
Kaushal Kumar Jha - ServiceNow Consultant - Lets connect on Linkedin: https://www.linkedin.com/in/kaushalkrjha/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-04-2025 09:46 AM
It is displaying this message in the portal and not showing the topic: ErrorGlideQuery undefined, maybe missing global qualifier
