I want to ask you a simple logic. In my servicenow instance, we have a field named as asset on ritm form and reference to the alm_hardware table which shows the records when click on magnifying glass, with reference qualifier. Same field we used in our sc_task through dot walk.. but whn user click on magnifying glass then it shows no records. But same on ritm it shows 10 records as per the reference qualifier.
Assistant
User
Script include reference qualifier is used. My point is when i select the asset from RITM it will automatically changed in sc task but when i search from sc task table then no records found in it. And whenever i open the dictionary for the asset field on sc task table then it shows the asset field created on ritm onlu
Assistant
In ServiceNow, reference fields utilize reference qualifiers to filter and limit the records shown in the selection list. Dot-walking allows fields in related tables to be accessed and used in your instance. When you experience an issue where a reference field works correctly on one form (e.g., RITM) but not on another (e.g., SC_Task), it can be due to a few common reasons:
Reference Qualifier Context: The reference qualifier you define needs to be valid in the context of where it is being used. If it references information specific to the RITM but is not appropriately altered for the SC_Task context, then it may result in no records being shown.
Field Inheritance and Dot-Walking: Ensure that the dot-walked field is appropriately set up and that the SC_Task form has access to the same related fields. There might be a problem with how the dot-walking is set or it might be that the script or qualifier does not account for dot-walked conditions properly.
Security Restrictions: There could be security restrictions or conditions in place (access controls, business rules, etc.) that impact the visibility of records when trying to resolve the reference through dot-walking.
Scripted Reference Qualifier: If a scripted reference qualifier is applied, ensure it is correctly handling the context of different records/forms (like RITM and SC_Task).
Troubleshooting Steps
Step 1: Check Reference Qualifier
Validate the reference qualifier used on RITM form and ensure it is applicable and correctly executing in the context of SC_Task as well.
Open the Field's Dictionary Entry:
Navigate to the RITM form dictionary entry for the asset field.
Note down the conditions/script used in the reference qualifier.
Verify Reference Qualifier on SC_Task:
If you are dot-walking to the asset field on the SC_Task, open the dictionary entry and check that the same reference qualifier is applied correctly.
Step 2: Test Dot-Walking
Test dot-walking separately by using scripts or UI actions to ensure that the target field on SC_Task can access the RITM's asset field correctly.
Step 3: Security and Access Controls
Check for any Access Control rules (ACLs) applied to the alm_hardware table and ensure they are not restricting the visibility of records when accessed from SC_Task.
Step 4: Use GlideRecord for Debugging
Insert temporary GlideRecord scripts in the background script or in a script include to fetch and verify if the records can be retrieved as expected.
javascript
var assetRecords = new GlideRecord('alm_hardware');
assetRecords.addQuery('referenceAlias', 'your condition'); // Use the proper condition you expect to use in the reference qualifier
assetRecords.query();
while (assetRecords.next()) {
gs.info('Found asset: ' + assetRecords.getValue('name'));
}
Step 5: Debug Logs
Enable and review debug logs to get insights into the evaluation process of your reference qualifier, dot-walking, and any potential issues at runtime.
If these steps don't resolve the issue, please provide additional details such as the reference qualifier script, specifics on the dot-walking setup, and any scripts used to ensure a deeper dive into the problem.
Given that a Script Include is used for the reference qualifier and the dot-walking seems to be correctly configured since the asset field value changes appropriately, the issue appears to be with the context in which the reference qualifier script is running. Below are detailed steps to ensure that the reference qualifier works properly in both RITM and SC_Task contexts, especially when accessed via dot-walking.
Step-by-Step Solution
Step 1: Validate the Script Include
First, let's review the Script Include that is being used as the reference qualifier. Ensure that it correctly handles the context of both RITM and SC_Task.
Open the Script Include:
Navigate to the Script Include in ServiceNow: System Definition > Script Includes.
Check the Script Logic:
Ensure the script accounts for the different contexts. You might need to modify it to handle RITM and SC_Task scenarios separately if not already done.
javascript
var MyReferenceQualifier = Class.create();
MyReferenceQualifier.prototype = {
initialize: function() {
},
// The function that gets invoked by the reference qualifier
getFilteredAssets: function(current) {
var answer = '';
// Example: Add a condition based on RITM and SC_Task context
if (current instanceof GlideRecord && current.getTableName() == 'sc_task') {
// Add conditions specific to SC_Task
// Example: restrict records visible to sc_task
answer = 'active=true'; // Replace with actual conditions
} else if (current instanceof GlideRecord && current.getTableName() == 'sc_req_item') {
// Add conditions specific to RITM
answer = 'active=true'; // Replace with actual conditions
}
return answer;
},
type: 'MyReferenceQualifier'
};
Step 2: Apply the Reference Qualifier
Ensure that the reference qualifier is applied correctly to the asset field in both the RITM and SC_Task forms.
For RITM Form:
Go to the Dictionary entry for the asset field in the sc_req_item table.
Ensure the Reference qualifier script points to the Script Include function, for example:
Go to the Dictionary entry for the asset field in the sc_task table.
Since it's a dot-walked reference, ensure the same reference qualifier script is used.
Step 3: Test the Configuration
Create a RITM Record:
Create or open an existing RITM record and set the asset field. Ensure it shows the expected 10 records based on the reference qualifier.
Create a SC_Task Record via a Workflow:
Create or open an SC_Task related to the RITM and see if the asset field gets the same 10 records when you click on the magnifying glass to search.
Step 4: Debugging
If the above steps don’t resolve the issue, add logging to the Script Include to see what conditions are being applied. For example:
javascript
var MyReferenceQualifier = Class.create();
MyReferenceQualifier.prototype = {
initialize: function() {
},
getFilteredAssets: function(current) {
var answer = '';
if (current instanceof GlideRecord && current.getTableName() == 'sc_task') {
// Logging for debugging
gs.info('SC_Task context');
// Add conditions specific to SC_Task
answer = 'active=true'; // Replace with actual conditions
} else if (current instanceof GlideRecord && current.getTableName() == 'sc_req_item') {
// Logging for debugging
gs.info('RITM context');
// Add conditions specific to RITM
answer = 'active=true'; // Replace with actual conditions
}
return answer;
},
type: 'MyReferenceQualifier'
};
Check the System Logs for any output from gs.info to ensure the context is being detected and handled as expected.
Final Tuning
If the script is working correctly and the correct conditions are applied, but no records show up, revisit any ACLs (Access Control Lists) for the alm_hardware table. Ensure that the user has the appropriate permissions to view the records in both contexts.
By ensuring the Script Include accounts for both the RITM and SC_Task contexts and correctly applying the reference qualifier, this should resolve the issue.