in catalog item there is one variable i need to see only active records in that servicenow
- User
in catalog item there is one variable i need to see only active records in that servicenow
- Assistant
To view only active records for a particular catalog item in ServiceNow, you would typically apply a filter based on the
Activefield within the relevant table. Here’s a step-by-step guide to view only active records:-
Navigate to the Correct Module:
- Log in to your ServiceNow instance.
- Go to the module that contains the records you want to filter. For catalog items, you might be working within the
Service Catalog > Catalog Definitions > Maintain Itemsmodule.
-
Open the List View:
- Once you're in the correct module, switch to the list view of the records (if you're not there already).
-
Create a Filter:
- At the top of the list, you’ll typically find a filter bar. If it's not visible, click on the filter icon or "Show Filter" to display it.
- Add a filter condition:
- Select the field you want to filter by. For active records, you'll use the field usually called
Active(or similar, depending on customization). - Set the condition to
Active is trueor selectActiveand entertrueor click the checkbox depending on your instance setup.
- Select the field you want to filter by. For active records, you'll use the field usually called
-
Apply the Filter:
- After setting up your filter conditions, click the search or filter button to apply the filter. The list should now display only the records where the
Activefield is true.
- After setting up your filter conditions, click the search or filter button to apply the filter. The list should now display only the records where the
-
Save the Filter (Optional):
- If you regularly need to view active items, you can save this filter for future use. Look for a save or bookmark option in the filter interface.
This process allows you to focus on active records and is a fundamental feature of ServiceNow's list functionality. If you're working in a custom table or the ServiceNow interface has been significantly customized, the exact steps may vary slightly.
-
- User
In catalog item there is one variable reference to alm hardware table and all hardware records is showing in this. I want to show only active records to the users if they select any value. How to do it via script
- Assistant
To restrict a reference variable in a ServiceNow catalog item to display only active records from the
alm_hardwaretable, you can use a Reference Qualifier. You can define a scripted Reference Qualifier to filter the results dynamically. Here’s how you can do this:-
Navigate to the Catalog Item Form:
- Log in to your ServiceNow instance.
- Navigate to the Service Catalog and find the catalog item you are working on.
-
Open the Variable:
- Open the record for the catalog item and go to the variables tab.
- Find and open the reference variable that points to the
alm_hardwaretable.
-
Set the Reference Qualifier:
- In the variable record, look for the field labeled "Reference qualifier."
- Set it to "Advanced" to enable scripting.
-
Write a Script for the Reference Qualifier:
- Click the "Reference qualifier script" field to open the script editor.
- Write a script to filter out only active records. Here's a simple example:
// The script must return a query string to filter records answer = 'active=true'; -
Save Changes:
- Save or update the variable record.
This script ensures that only records from the
alm_hardwaretable withactive=trueare shown in the reference field dropdown when users interact with the catalog item.Important Considerations:
-
Permissions: Ensure that users have the appropriate permissions to see and query the
alm_hardwaretable and its fields. -
Data Consistency: Make sure that the
Activefield used in the script is the correct field name and is consistently maintained across the records in thealm_hardwaretable. -
Testing: After implementing the script, test it thoroughly with different user roles to confirm that the filtering behaves as expected.
By using a scripted reference qualifier, you can dynamically control which records appear, enhancing the user experience and maintaining data relevance.
-
- User
I am not able to edit reference qualifiers , please suggest any other method
- Assistant
If you are unable to edit the reference qualifiers directly through the catalog item variable configuration in ServiceNow, you might still have a few alternative approaches to achieve filtering:
Use a Client Script:
-
Create a Client Script:
- Navigate to the catalog item and go to the
Catalog Client Scriptsrelated list. - Click "New" to create a new client script.
- Navigate to the catalog item and go to the
-
Configure the Client Script:
- Type: Set this to "onLoad" or "onChange", depending on when you want the filter to be applied.
- Applies To: Catalog Item.
- Name: Provide a meaningful name for the script.
- Script: Implement a script that filters the reference field using GlideForm. Below is a sample script to achieve the restriction:
function onLoad() { // 'current' is the GlideForm instance representing the current catalog item form var ga = new GlideAjax('GetActiveHardware'); // Server-side script include ga.addParam('sysparm_name', 'getActiveHardware'); ga.getXMLAnswer(function(response) { var filter = response || ''; // Default to empty string if no response // Replace 'your_reference_variable_name' with the actual name of your reference variable g_form.setDependent('your_reference_variable_name', filter); }); } -
Create a Script Include:
- If you're using GlideAjax, you need a script include on the server-side to return the filtered sys_ids or a query:
var GetActiveHardware = Class.create(); GetActiveHardware.prototype = Object.extendsObject(AbstractAjaxProcessor, { getActiveHardware: function() { // Craft a query to fetch active hardware sys_ids var query = 'active=true'; var gr = new GlideRecord('alm_hardware'); gr.addEncodedQuery(query); gr.query(); var sysIdList = []; while (gr.next()) { sysIdList.push(gr.getValue('sys_id')); } // Return the sys_id list as a semicolon-delimited string, or adapt to your needs return sysIdList.join(','); } });
Considerations:
-
Client Scripting Limitations: It's essential to ensure your users have appropriate permissions to execute scripts, and client scripts should be optimized for performance.
-
Test Thoroughly: After implementing changes, test extensively across different user roles to ensure the functionality works as expected and does not introduce any performance issues or errors on the catalog form.
This approach using client scripts combined with a server-side Script Include can help you filter the reference fields even when direct editing of the reference qualifier is restricted or non-functional due to permissions or other constraints.
-