How to find value in any position on a field?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-11-2024 11:43 AM
I need to find the name of someone independent if the value is in the beggin or on the middle or on the final name, is a widget on portal, and I cannot find if someone has a name "Maria Silva Santos", if I insert "Santos" it cannot find.
Is possible to add somenthing in default-query to help me?
This is my HTML :
<div>
<sn-record-picker field="c.user" table="'sys_user'" default-query="''" display-field="'name'" value-field="'sys_id'"
display-fields="'email'" search-fields="'name'" page-size="100">
</sn-record-picker>
<div id="org_chart" class="org-chart"></div>
<button name="zoomin" ng-click="c.zoomIn()" class="btn btn-primary" aria-label="${Zoom in}" data-toggle="tooltip" title="${Zoom in}"><span><i class="fa fa-search-plus"></i></span></button>
<button name="zoomout" ng-click="c.zoomOut()" class="btn btn-primary" aria-label="${Zoom out}" data-toggle="tooltip" title="${Zoom out}"><span><i class="fa fa-search-minus"></i></span></button>
</div>
CLIENT SCRIPT:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-11-2024 12:33 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-11-2024 01:33 PM
To allow searching for a name even if it appears at any position within the field value, you can use the ServiceNow encoded query syntax in the default-query attribute of the <sn-record-picker> element. The encoded query syntax allows you to create complex queries to filter records.
In your case, you want to search for a name regardless of its position within the name field of the sys_user table. Here's how you can modify the default-query attribute:
<sn-record-picker field="c.user" table="'sys_user'" default-query="'nameLIKE*${c.searchQuery}*'" display-field="'name'" value-field="'sys_id'" display-fields="'email'" search-fields="'name'" page-size="100">
</sn-record-picker>
In this modified version:
- nameLIKE*${c.searchQuery}* is the encoded query syntax used in the default-query attribute.
- name is the field you want to search within.
- LIKE*${c.searchQuery}* specifies that you want to perform a wildcard search for the value of c.searchQuery within the name field. The asterisks (*) act as wildcards, allowing the search term to match at any position within the field value.
Now, in your client script, you need to set the value of c.searchQuery whenever the user types in the search input field. You can achieve this by adding an ng-model attribute to your search input field and then updating c.searchQuery accordingly. Here's an example of how you can modify your HTML:
<input type="text" ng-model="c.searchQuery" placeholder="Search for a user">
Make sure to update your client script to handle the changes to c.searchQuery appropriately. This will allow users to search for a user's name regardless of its position within the field value.
🙂