Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Reference field values are not visible in Portal

Ranjit Singh Ra
Tera Expert

I have an HR Service (Scope - Human Resources: Core) in the ESC Portal. 

I have created a custom table "Routing ID" in Global scope which extends CMDB CI Table. 

 

I have a variable in the HR Service which is referenced to the custom table. I have records in the custom table but still I am unable to see any records from the Portal. It says "no matching records found"

 

I have given the custom table Read ACL to my user, and also given the cmdb_read role to my user, still the same issue.

 

Please let me know what I can check to get this fixed.

 

Thank you.

16 REPLIES 16

NaveedK18654415
Tera Contributor

Hi Ranjit,

 

Did you get the solution for this? I am also facing the same issue . In portal, values are not populating for reference field. If you got the solution, pls post here. That would be very helpful.

MaxMixali
Kilo Sage

Per creare Application Access:

  1. Vai a: System Applications > Application Cross-Scope Access
  2. New
  3. Source Scope: Human Resources: Core (sn_hr_core)
  4. Operation: Read
  5. Target: Seleziona la tua tabella custom u_routing_id
  6. Status: Allowed

3. Verifica la Variabile del Catalog Item

 
 
javascript
// Controlla la configurazione della variabile
// Service Catalog > Catalog Variables

// Parametri da verificare:
// - Type: Reference
// - Reference: u_routing_id (tua tabella custom)
// - Reference qualifier: (lascia vuoto per ora)
// - Read roles: (verifica che sia vuoto o compatibile)

4. Verifica i Record nella Tabella

Esegui questo script in Background Scripts:

 
 
javascript
// Verifica che i record esistano e siano accessibili
var gr = new GlideRecord('u_routing_id');
gr.query();
gs.info('Total records in u_routing_id: ' + gr.getRowCount());

while (gr.next()) {
    gs.info('Record: ' + gr.sys_id + ' - ' + gr.getDisplayValue());
}

// Verifica se l'utente può leggerli
var userName = 'nome.utente'; // Sostituisci con il tuo username
gs.info('User can read: ' + gr.canRead());

// Impersona l'utente e riprova
var user = new GlideRecord('sys_user');
user.addQuery('user_name', userName);
user.query();
if (user.next()) {
    var impersonator = new GlideImpersonate();
    impersonator.impersonate(user.sys_id);
    
    var testGr = new GlideRecord('u_routing_id');
    testGr.query();
    gs.info('Records visible as ' + userName + ': ' + testGr.getRowCount());
    
    impersonator.unimpersonate();
}

5. Verifica Dictionary Entry

 
 
javascript
// Vai a: System Definition > Dictionary
// Cerca: u_routing_id

// Verifica che il campo display (name o altri) sia:
// - Active: true
// - Read only: false

6. Controlla Reference Qualifier sulla Variabile

Se hai un reference qualifier, potrebbe filtrare troppo:

 
 
javascript
// Nella variabile, controlla:
// - Reference qualifier: 
//   Se presente, prova a rimuoverlo temporaneamente
//   Oppure usa: javascript: 'active=true'

7. Verifica CMDB ACL (Parent Table)

Dato che la tua tabella estende cmdb_ci:

 
 
javascript
// Background Script per verificare
var gr = new GlideRecord('u_routing_id');
gr.setLimit(1);
gr.query();

if (gr.next()) {
    gs.info('Can read CMDB CI: ' + new GlideRecord('cmdb_ci').get(gr.sys_id));
    gs.info('Has cmdb_read role: ' + gs.hasRole('cmdb_read'));
    gs.info('User roles: ' + gs.getUser().getRoles());
}

8. Clear Cache

A volte il problema è solo cache:

  1. Vai a: System Diagnostics > Cache Inspect
  2. Cerca: u_routing_id
  3. Flush della cache
  4. Oppure: cache.flush nella cache

9. Soluzione Rapida - Script da Eseguire

Esegui questo script in Background Scripts per configurare tutto:

 
 
javascript
// === CONFIGURAZIONE AUTOMATICA ===
var tableName = 'u_routing_id'; // Nome della tua tabella
var hrScope = 'sn_hr_core'; // Scope HR

// 1. Crea/Aggiorna ACL di Read (Public)
var acl = new GlideRecord('sys_security_acl');
acl.addQuery('name', tableName);
acl.addQuery('operation', 'read');
acl.query();

if (!acl.next()) {
    acl.initialize();
    acl.setValue('name', tableName);
    acl.setValue('operation', 'read');
    acl.setValue('active', true);
    acl.setValue('admin_overrides', true);
    acl.setValue('description', 'Auto-created for portal access');
    acl.insert();
    gs.info('ACL created');
} else {
    gs.info('ACL already exists');
}

// 2. Crea Application Cross-Scope Access
var appAccess = new GlideRecord('sys_scope_privilege');
appAccess.addQuery('source_scope.scope', hrScope);
appAccess.addQuery('target_name', tableName);
appAccess.addQuery('operation', 'read');
appAccess.query();

if (!appAccess.next()) {
    var hrScopeGr = new GlideRecord('sys_scope');
    hrScopeGr.addQuery('scope', hrScope);
    hrScopeGr.query();
    
    if (hrScopeGr.next()) {
        appAccess.initialize();
        appAccess.setValue('source_scope', hrScopeGr.sys_id);
        appAccess.setValue('target_name', tableName);
        appAccess.setValue('target_type', 'sys_db_object');
        appAccess.setValue('operation', 'read');
        appAccess.setValue('status', 'allowed');
        appAccess.insert();
        gs.info('Application Access created');
    }
} else {
    gs.info('Application Access already exists');
}

// 3. Verifica record
var count = new GlideRecord(tableName);
count.query();
gs.info('Total records in table: ' + count.getRowCount());

gs.info('=== CONFIGURATION COMPLETED ===');
gs.info('Clear cache and test again');

10. Test dal Portal

Dopo aver applicato le fix, testa:

  1. Logout/Login dal portale
  2. Apri il HR Service nel portale
  3. Prova la variabile reference
  4. Se ancora non funziona, apri Developer Tools (F12) e controlla la Console per errori JavaScript