> ## Documentation Index
> Fetch the complete documentation index at: https://docs.abbyy.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Sample database search script

> Sample web custom action script that searches a data set from the FlexiCapture Web Verification Station and copies the found value into the current field.

This sample script searches a data set from the Web Verification Station and copies the found value into the current field.

## Create a data set

Before you configure the script, create a data set for it to search:

<Steps>
  <Step title="Open the document definitions">
    Open the Project Setup Station and click **Project → Document Definitions**.
  </Step>

  <Step title="Add a data set">
    Click **Document Definition → Document Definition Properties**, open the **Data Sets** tab, and click **Add**.
  </Step>

  <Step title="Create records">
    Create a data set, add a few records, and click **Close**.
  </Step>
</Steps>

You add this script as a user script for the Web Verification Station. For more information, see [User scripts for the Web Verification Station](/flexi-capture/appendix/scripts/web-custom-action-script).

## Sample script

```javascript theme={null}
//DataSet Name
var dbCacheName = 'DataSet1';
//Field in dataset, used to replace current field value
var fieldNameInCache = 'Field2';
var self = this;
var styles = {
    display: 'block',
    position: 'absolute',
    top: '0px',
    bottom: '0px',
    left: '0px',
    right: '0px',
    width: '100%',
    height: '100%',
    border: '0',
    overflow: 'hidden',
    'overflow-x': 'hidden',
    'overflow-y': 'hidden',
    'z-index': '10000'
}
var newValueToInsert = '';
// Sets iframe styles
setStyles(
    styles,
    function() {
        //Dialog markup
        var windowMarkup = "<div class='frame'><div class='searchField'><input id='searchValue' /><button id='searchButton'>Search</button></div><div id='recordspanel'><table id='resultspreview'></table><div id='norecord'>No records found</div></div><div class='buttonsfield'><button id='confirm'>Ok</button><button id='cancel'>Cancel</button></div></div>";
        //Dialog styles
        var css = "<style>body{width:100vw;height:100vh;background:rgba(0,0,0,0.1);margin:0;padding:0;display:flex;align-items:center;justify-content:center;}.frame{width:400px;max-height:80vh;background:white;min-height:200px;padding:50px;}#norecord{display:none;}#searchValue{width:calc(100% - 60px);}#cancel{margin-left:20px;}.buttonsfield{display:flex;justify-content:flex-end;height:25px;}.bolded{font-weight:bold;}button{width:60px;}#confirm{display:none;}#recordspanel{min-height:145px;padding: 10px 0;}#searchfield{height:30px;}</style>";
        //Set styles
        $('head').append(css);
        //Creates dom in iframe
        $("body").append(windowMarkup);
        // Search button click
        $('#searchButton').click(function () {
            //Look in Dictionary
            getDict(
                {
                    cacheName: dbCacheName, //dataset name
                    filters: [{ FieldName: "", FieldValue: $('#searchValue').val() }] //fields to search
                },
                function (result) {
                    //Records  rows from dataset
                    var records = result.detail.result;
                    //First row description
                    var firstRecord = records[0];
                    //hide 'table' and 'ok' button if no result is found
                    if (!firstRecord && !firstRecord.BoldMask){
                        $('#resultspreview').hide();
                        $('#norecord').show();
                        $('#confirm').hide();
                    } else {
                        $('#resultspreview').show();
                        $('#confirm').show();
                        $('#norecord').hide();
                        $('#resultspreview').html('');
                        firstRecord.forEach(function (recordData) {
                            if (fieldNameInCache === recordData.FieldName) {
                                newValueToInsert = recordData.FieldValue;
                            }
                            $('#resultspreview')
                                .append('<tr class="' +
                                    (fieldNameInCache === recordData.FieldName ? 'bolded' : '') +
                                    '"><td>' +
                                    recordData.FieldName +
                                    '</td><td>' +
                                    recordData.FieldValue +
                                    '</td></tr>');
                        });
                    }
                });
        });
        //On 'ok' button click
        $('#confirm').click(function () {
            if (newValueToInsert) {
                //Set value to current field
                setCurrentFieldValue(newValueToInsert);
                //Save and close iframe
                save();
            }
        });
        //On 'cancel' button click
        $('#cancel').click(function () {
            cancel();
        });
    });
```

You can also find this sample script at `https://<ApplicationServer>/FlexiCapture12/Verification/Scripts/CustomScripts/customActionLookup.js`, where `<ApplicationServer>` is the name of the computer where the Application Server is installed.

Replace the values in these lines:

* `var dbCacheName = 'DataSet1';` — `DataSet1` is the name of the data set you created.
* `var fieldNameInCache = 'Field2';` — `Field2` is the name of the data set field that contains the value to copy.
