- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-14-2025 01:57 AM
How to enhance the search so that if a last name is entered, the user name will come up.
Currently it' is working with first name.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-14-2025 02:47 AM
Hio @VanishreeG
You can add an attribute in the variable definition to search by the last name as well. Give last_name as the value for the attribute ref_ac_columns. [Change the fields after ref_ac_columns to whatever fields you want on the User table.]
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.
Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]
****************************************************************************************************************
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-14-2025 03:03 AM
Hi @VanishreeG,
as per your screenshot to @Dr Atul G- LNG. You are referring to a “catalog item”
please go to your catalog item, open the variable where you want to add more fields to the search.
adjust the attributes as follow for your variable:
ref_auto_completer=AJAXTableCompleter,ref_ac_columns=first_name;last_name,ref_ac_columns_search=true
this is where the “variable attributes” is located:
If you found this helpful, please hit the thumbs-up button and mark as correct. That helps others find their solutions.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-14-2025 02:14 AM
Hi VanishreeG,
To enhance the search functionality so that a last name can trigger a username result, similar to how the search currently works with a first name, you'll need to modify the search logic to account for last names. Here’s how you can approach it:
Update the search function: Modify the search function so it checks for both first name and last name, or searches for the input in both fields (first name and last name).
Search Strategy:
If the input is a first name, the system should search for matches in the first name field (which is already working).
If the input is a last name, the system should search for matches in the last name field.
Optionally, if the user enters both first and last names, the system should search in both fields and return the relevant result.
Example Solution in Pseudocode:
def search_user(search_input):
# Check if the input contains a space (assumes it could be first and last name)
if " " in search_input:
first_name, last_name = search_input.split(" ", 1)
result = search_in_both(first_name, last_name)
else:
# Check if it's a first name or last name
result = search_in_first_name(search_input) or search_in_last_name(search_input)
return result
def search_in_first_name(first_name):
# Logic to search for a user by first name
return find_user_by_first_name(first_name)
def search_in_last_name(last_name):
# Logic to search for a user by last name
return find_user_by_last_name(last_name)
def search_in_both(first_name, last_name):
# Search logic when both first and last name are provided
user_by_first = find_user_by_first_name(first_name)
user_by_last = find_user_by_last_name(last_name)
# Merge results if needed or prioritize one
return merge_results(user_by_first, user_by_last)
Considerations:
Handling Spaces: If a user enters both first and last names, you need to handle the space in between (as shown in the pseudocode).
Prioritization: You might want to prioritize results from one field over the other or merge results.
Edge Cases: Handle cases where no user is found for either the first or last name.
Example UI/UX: Update the UI so that the user understands they can enter either a first or last name, or both. If both are entered, the search will intelligently look for matches in both fields.
Kindly mark it as "Accepted Solution"/"helpful", as it resolves your query. Please press like button for the resolution provided.
With Regards,
Krishna Kumar M - Talk with AIT3ch
LinkedIn: https://www.linkedin.com/in/mkrishnak4/
YouTube: https://www.youtube.com/@KrishAIT3CH
Topmate: https://topmate.io/mkrishnak4 [ Connect for 1-1 Session]
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-14-2025 02:33 AM
Hi,
In which script we need add this.
could you could you elaborate more about the code ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-14-2025 02:30 AM
Hi @VanishreeG,
Do you have AI Search enabled?
Please:
- Go to Service Portal > Search > Search Sources
- Check if you have any entry for the users
- Adjust the script so that it includes the last name when checking
Please share the script to assist further on this?
If you found this helpful, please hit the thumbs-up button and mark as correct. That helps others find their solutions.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-14-2025 02:35 AM
Hi @VanishreeG
Your question is very unclear.. portal is wide where you search
In Search Bar
or in catalog varaible?
Any screenshot?
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.
Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]
****************************************************************************************************************