Extending Custom SearchMode to work with xClass Search

In order to use xClass criteria with a custom search mode without validation errors, it is necessary to extend the testAmlForCompatibility, getAml, and setAml functions of the custom search mode:

SearchMode:

JavaScript

function MyCustomSearch(searchContainer) {

    // This flag enables the possibility to use xClass Search with this SearchMode
                                            

    this.supportXClassSearch = true;
                                            

 

    // MyCustomSearch initialization code
                                            

    SearchMode.prototype.constructor.call(this, searchContainer, aras);
                                            

}

 

MyCustomSearch.prototype = new SearchMode;

MyCustomSearch.prototype.setAml = function AMLSearchMode_setAml(searchAML) {

    let xClassCriteria;

    // call base setAml function to load searchAML into the current query item
                                            

    SearchMode.prototype.setAml.call(this, searchAML);
                                            

    // if current SearchMode supports xClassSearch
                                            

    if (this.supportXClassSearch) {
                                            

        // try to find xClassSearch criteria
                                            

        xClassCriteria = this.currQryItem.item.selectSingleNode(this.xClassSearchCriteriaXPath);
                                            

        if (xClassCriteria) {
                                            

            // if xClassSearch criteria exists then remove it from the current query item
                                            

            xClassCriteria = this.currQryItem.item.removeChild(xClassCriteria);
                                            

            // replace searchAML by AML without xClassSearch criteria
                                            

            searchAML = this.currQryItem.item.xml;
                                            

        }
                                            

    }

    // some business logic of custom SearchMode to populate it based on provided searchAML
                                            

    // if xClassSearch criteria was found previously
                                            

    if (xClassCriteria) {
                                            

        // append stored xClassSearch criteria to the current query item
                                            

        this.currQryItem.item.appendChild(this.currQryItem.dom.importNode(xClassCriteria, true));
                                            

    }

}

MyCustomSearch.prototype.getAml = function AMLSearchMode_getAml() {
                                            

    let xClassCriteria;

    // if current SearchMode supports xClassSearch
                                            

    if (this.supportXClassSearch) {
                                            

        // try to find xClassSearch criteria
                                            

        xClassCriteria = this.currQryItem.item.selectSingleNode(this.xClassSearchCriteriaXPath);
                                            

        if (xClassCriteria) {
                                            

            // if xClassSearch criteria exists then remove it from the current query item
                                            

            xClassCriteria = this.currQryItem.item.removeChild(xClassCriteria);
                                            

        }
                                            

    }

    // some business logic to populate current query item by search criteria for custom SearchMode
                                            

    // if xClassSearch criteria was found previously
                                            

    if (xClassCriteria) {
                                            

        // append stored xClassSearch criteria to the current query item
                                            

        this.currQryItem.item.appendChild(xClassCriteria);
                                            

    }

}

 

MyCustomSearch.prototype.testAmlForCompatibility = function (searchAml) {
                                            

    let searchQuery = searchAml;

    if (this.supportXClassSearch) {
                                            

        // if current SearchMode supports xClassSearch
                                            

        const queryDom = this.aras.createXMLDocument();

        queryDom.loadXML(searchAml);
                                            

        // try to find xClassSearch criteria
                                            

        const xClassCriteria = queryDom.documentElement.selectSingleNode(this.xClassSearchCriteriaXPath);

        if (xClassCriteria) {
                                            

            // if xClassSearch criteria exists then remove it from AML which should be validated
                                            

            queryDom.documentElement.removeChild(xClassCriteria);
                                            

            searchQuery = queryDom.documentElement.xml;
                                            

        }
                                            

    }

    return SearchMode.prototype.testAmlForCompatibility.call(this, searchQuery);

}