- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-23-2023 11:37 PM
Hello Team,
I have a reference field with table as TASK. I have another variable on form which gives option to select the table name for the user (incident, service request, problem).
Whenever user select table name, only those record should be visible in reference field variable, can we achieve this.
Please let me know the approach.
Thank you
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-24-2023 06:00 AM
Hi @Sunil31
Why not? there you go!
javascript: current.u_task_type ? 'active=true^assigned_toDYNAMIC90d1921e5f510100a9ad2572f2b477fe^sys_class_name=' + current.u_task_type : 'sys_class_name=-1';
Cheers,
Tai Vu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-23-2023 11:43 PM - edited 10-23-2023 11:44 PM
Hi @Sunil31,
Yes, you can achieve this in ServiceNow by using Reference Qualifiers. Reference Qualifiers are used to filter the records that are available in a reference field based on certain conditions, including the value of other variables. In your case, you want to filter records in a reference field based on the table selected by the user.
Navigate to the reference field in the form designer.
- In the reference field's settings, find the "Advanced Reference Qualifier" field or similar options, which allow you to define a script.
- Create a script that evaluates the value of the variable, which allows the user to select the table name. You'll use this variable to determine the filter condition.
- Depending on the table selected by the user, you should set a filter condition that restricts the records displayed in the reference field.
Here's a sample script:
function getTable() {
// Get the selected table from the variable (assuming your variable's name is 'table_selection')
var selectedTable = current.variables.table_selection;
// Define the filter condition based on the selected table
if (selectedTable == 'incident') {
return 'active=true^table=incident';
} else if (selectedTable == 'service_request') {
return 'active=true^table=service_request';
} else if (selectedTable == 'problem') {
return 'active=true^table=problem';
} else {
return 'active=true^table=task'; // Default to the 'TASK' table
}
}
// Return the filter condition
return getTable();
Once you've created the script, set the reference field's Advanced Reference Qualifier to the script you created.
Test the form by selecting different table names in your variable and observe how the reference field's options change accordingly.
This approach will dynamically filter the records in the reference field based on the user's selection of the table name variable. The script provided is a basic example; you may need to adapt it to your specific requirements, and you should always consider security and access control when implementing reference qualifiers.
If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.
Thanks,
Arsalan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-24-2023 01:11 AM
Thank you.. im checking the above approach. If im not wrong, then we only need Script include. No need of a client script. Please correct me if im wrong.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-24-2023 12:46 AM
Hi @Sunil31
Let's try this approach.
Sample script:
javascript: current.variables.task_class_name ? 'sys_class_name=' + current.variables.task_class_name : '';
Enjoy result:
Let me know if it works for you.
Cheers,
Tai Vu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-24-2023 01:14 AM
hello @Tai Vu ,
Thank you for this approach. However could you please correct me if my understanding is correct.
I have variable as 'task_type' which holds 3 choices. (incident,sc_req_item,problem).
So my reference field qualifier will be like below
javascript: current.variables.task_type ? 'sys_class_name=' + current.variables.task_type : '';
Somehow im not getting expected result. ig im doing something wrong.