Article

Add lookup field into input box

Add code below into methods section and bind openInputBox method.

Example: lookup fields to Contact and Account tables.

Pre-condition: add localizableStrings to your schema (UsrContactCaption, UsrAccountCaption, UsrInputBoxCaption).

openInputBox: function() {
    this.set("UsrContactCollection", new Terrasoft.Collection());
    this.set("UsrAccountCollection", new Terrasoft.Collection());
    this.set("UsrContact", null);
    this.set("UsrAccount", null);
    var controls = {
        "UsrContact": {
            dataValueType: Terrasoft.DataValueType.ENUM,
            isRequired: true,
            caption: resources.localizableStrings.UsrContactCaption,
            value: {
                bindTo: "UsrContact"
            },
            customConfig: {
                tag: "Contact",
                list: {
                    bindTo: "UsrContactCollection"
                },
                prepareList: {
                    bindTo: "getCollectionValues"
                },
                loadNextPage: {
                    bindTo: "loadCollectionNextPage"
                }
            }
        },
        "UsrAccount": {
            dataValueType: Terrasoft.DataValueType.ENUM,
            isRequired: true,
            caption: resources.localizableStrings.UsrAccountCaption,
            value: {
                bindTo: "UsrAccount"
            },
            customConfig: {
                tag: "Account",
                list: {
                    bindTo: "UsrAccountCollection"
                },
                prepareList: {
                    bindTo: "getCollectionValues"
                },
                loadNextPage: {
                    bindTo: "loadCollectionNextPage"
                }
            }
        }
    };
    Terrasoft.utils.inputBox(resources.localizableStrings.UsrInputBoxCaption,
        this.openInputBoxHandler,
        [Terrasoft.MessageBoxButtons.OK, Terrasoft.MessageBoxButtons.CANCEL],
        this,
        controls
    );
    Terrasoft.each(Terrasoft.MessageBox.controlArray, function(item) {
        item.control.bind(this);
    }, this);
},
getCollectionValues: function(filter, list, tag) {
    if (Ext.isEmpty(list)) {
        return;
    }
    list.clear();
    var esq = Ext.create("Terrasoft.EntitySchemaQuery", {
        rootSchemaName: tag,
        isPageable: true,
        rowCount: 20
    });
    this.buildCollectionQuery(esq, list, filter, tag);
},
loadCollectionNextPage: function(listParams, tag) {
    if (!this.get("CanLoadMore" + tag)) {
        return;
    }
    var esq = Ext.create("Terrasoft.EntitySchemaQuery", {
        rootSchemaName: tag,
        isPageable: true,
        rowCount: 20,
        rowsOffset: listParams.listView.collectionItemsCount
    });
    this.buildCollectionQuery(esq, listParams.list, listParams.filterValue, tag);
},
buildCollectionQuery: function(esq, list, filter, tag) {
    esq.addMacrosColumn(Terrasoft.QueryMacrosType.PRIMARY_COLUMN, "value");
    var orderColumn = esq.addMacrosColumn(Terrasoft.QueryMacrosType.PRIMARY_DISPLAY_COLUMN, "displayValue");
    orderColumn.orderDirection = Terrasoft.OrderDirection.ASC;
    esq.filters.addItem(esq.createPrimaryDisplayColumnFilterWithParameter(
        Terrasoft.ComparisonType.START_WITH, filter, Terrasoft.DataValueType.TEXT));
    esq.getEntityCollection(function(response) {
        if (response && response.success) {
            var preObject = {};
            response.collection.each(function(item) {
                preObject[item.get("value")] = item.values;
            }, this);
            list.loadAll(preObject);
            this.set("CanLoadMore" + tag, response.collection.getCount() === 20);
        }
    }, this);
},
openInputBoxHandler: function(returnCode, controlData) {
    if (Terrasoft.MessageBoxButtons.OK.returnCode === returnCode) {
        // TODO: your code here
    }
}

 

Like 0

Like

Share

2 comments

Hi 

I am using [Country ] and [City] lookup in the input box, But I have to apply the filter on these lookup. 



How is it possible to apply filter on lookups fields in input box ?



Many Thanks.

Dear Akshit,

 

In order to apply filtration over a lookup field in the InputBox please add the following code to the “buildCollectionQuery” method:



            buildCollectionQuery: function(esq, list, filter, tag) {

               esq.addMacrosColumn(Terrasoft.QueryMacrosType.PRIMARY_COLUMN, "value");

               var orderColumn = esq.addMacrosColumn(Terrasoft.QueryMacrosType.PRIMARY_DISPLAY_COLUMN, "displayValue");

               orderColumn.orderDirection = Terrasoft.OrderDirection.ASC;

               esq.filters.addItem(esq.createPrimaryDisplayColumnFilterWithParameter(

                   Terrasoft.ComparisonType.START_WITH, filter, Terrasoft.DataValueType.TEXT));

               esq.filters.addItem(esq.createColumnInFilterWithParameters("Name",

               ["Australia", "United States"]));


               esq.getEntityCollection(function(response) {

                   if (response.success) {

                       var preObject = {};

                       response.collection.each(function(item) {

                           preObject[item.get("value")] = item.values;

                       }, this);

                       list.loadAll(preObject);

                       this.set("CanLoadMore" + tag, response.collection.getCount() === 20);

                   }

               }, this);

            },



Please see the screenshot with the result https://prnt.sc/rtvqvm 



Additionally, please find more information about filtration in esq in the article by the link below:



https://academy.creatio.com/documents/technic-sdk/7-15/entityschemaquery-class-filters-handling

 

Best regards,

Norton

Show all comments