How to find value in any position on a field?

Adrieli Paczkow
Tera Contributor

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:

function ($scope, $location, $http, spUtil, $timeout) {
 
var c = this;
var $ = go.GraphObject.make;
 
c.user = {
displayValue: $scope.data.name,
value: $scope.data.start,
name: 'user'
};
 
console.log("TESTE FUNCTION " + $location);
 
// base user changed, reload page
$scope.$on("field.change", function(evt, parms) {
if (parms.field.name != 'user')
return;
 
var s = $location.search();
s.p = parms.newValue;
$location.search(s);
});
 
 
$timeout(function() {
c.diagram = $(go.Diagram, 'org_chart', {
mouseWheelBehavior: go.ToolManager.WheelZoom,
layout: $(go.TreeLayout, evalGoCode(c.options.tree_layout)) // use a TreeLayout to position all of the nodes
});
 
makeTemplate(c.diagram);
 
// create the Model with data for the tree, and assign to the Diagram
c.diagram.model = $(go.TreeModel, {
nodeParentKeyProperty: "manager", // this property refers to the parent node data
nodeDataArray: $scope.data.nodes
});
 
});
 
c.zoomIn = function() {
c.diagram.commandHandler.increaseZoom()
}
 
c.zoomOut = function() {
c.diagram.commandHandler.decreaseZoom()
}
 
// When a Node is double clicked, open the user record for the person in a new window
function nodeClick(event, node) {
window.open(spUtil.format($scope.options.url, {sys_id: node.data.key, page: c.options.page}));
}
 
function makeTemplate(diagram) {
diagram.nodeTemplate =  $(go.Node, "Auto", angular.extend({click: nodeClick}, evalGoCode(c.options.node_layout)),
$(go.Shape, "Rectangle", new go.Binding("fill", "color")), // the outer shape for the node, surrounding the Table
$(go.Panel, "Horizontal",$(go.Picture, evalGoCode(c.options.picture_layout), new go.Binding("source", "photo")), panel()));
diagram.linkTemplate = $(go.Link, go.Link.Orthogonal,{ selectable: false }, $(go.Shape, evalGoCode(c.options.line) )); // the default black link shape
}
 
function evalGoCode(item) {
for (var x in item) {
var re = /{([^}]+)?}/g, match;
while (match = new RegExp(re).exec(item[x])) {
item[x] = eval(match[1])
}
}
 
return item;
}
 
function panel() {
var opts = [
go.Panel, "Table", evalGoCode(c.options.table_layout),
$(go.RowColumnDefinition, evalGoCode(c.options.row_layout))];
var item;
for (var fieldName in c.options.card_fields) {
item = c.options.card_fields[fieldName];
evalGoCode(item);
opts.push($(go.TextBlock, item, new go.Binding("text", fieldName)))
}
return $.apply(null, opts);
}
 
}
2 REPLIES 2

Sohithanjan G
Kilo Sage
Kilo Sage

Hi @Adrieli Paczkow 

 

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.

 

🙂

Please mark as Accepted Solution if this solves your query and HIT Helpful if you find my answer helped you. This will help other community mates too..:)