Question

LOOKUP LIST NOT POPULATED IN INPUT BOX (SectionSchema)

Hi,

I am trying to update a lookup field linked to Owner field of Accounts (Lookup to Contacts) for multiple records using an input box, which is added as custom action. But, the list of records are not displaying either by typing in the field or clicking on magnifying glass icon.

 

I have tried multiple way to bind attributes and diff but no progress, therefore I have attached the code snippet of this custom action for reference.

 

I appreciate if you can suggest a way to tackle this issue.

Thanks,

 

File attachments
Like 0

Like

4 comments
Best reply

Hi Kavian,

 

The code below will do the trick:

define("AccountSectionV2", [], function() {
	return {
		entitySchemaName: "Account",
		details: /**SCHEMA_DETAILS*/{}/**SCHEMA_DETAILS*/,
		diff: /**SCHEMA_DIFF*/[]/**SCHEMA_DIFF*/,
		attributes:{},
		methods: {
			updateAccount: function(callback, autoIds, selectedContact){
				var update = Ext.create("Terrasoft.UpdateQuery", {
                            rootSchemaName: "Account"
                        });
				var filters = Terrasoft.createFilterGroup();
				filters.logicalOperation = Terrasoft.LogicalOperatorType.OR;
				autoIds.forEach(function(item) {
					var accountIdFilter = update.createColumnFilterWithParameter(Terrasoft.ComparisonType.EQUAL, "Id", item);
					filters.add("AccountIdFilter" + item, accountIdFilter);
				}, this);
				update.filters.add(filters);
				update.setParameterValue("Owner", selectedContact, Terrasoft.DataValueType.LOOKUP);
				update.execute(function(result) {
					callback.call(this, result);
				}, this);
			},
			getSectionActions: function() {
				var actionMenuItems = this.callParent(arguments);
				actionMenuItems.addItem(this.getButtonMenuItem({
					"Caption": {bindTo: "Resources.Strings.MultiplyChangeAction"},
					"Click": {bindTo: "showOwnerInfo"}
				}));
				return actionMenuItems;
			},
			showOwnerInfo: function() {
                var caption = "Select an owner";
                var ContactList;
                this.set("ContactList", new Terrasoft.Collection());
                var controls = {
                    "Owner": {
                        dataValueType: Terrasoft.DataValueType.ENUM,
                        isRequired: true,
                        caption: "Owner",
                        value: {
                            bindTo: "Contact"
                        },
                        customConfig: {
                            list: {
                                bindTo: "ContactList"
                            },
                            prepareList: {
                                bindTo: "onPrepareContactList"
                            }
                        }
                    }
                };
                var ownerInputBoxHandler = this.ownerInputBoxHandler.bind(this);
                Terrasoft.utils.inputBox(caption, ownerInputBoxHandler, [
					{
						className: "Terrasoft.Button",
						caption: "ASSIGN",
						returnCode: "ok"
					}, "cancel"
				], this, controls);
                Terrasoft.each(Terrasoft.MessageBox.controlArray, function(item){
                    item.control.bind(this);
                }, this);
            },
            onPrepareContactList: function(){
                var esq = this.Ext.create("Terrasoft.EntitySchemaQuery", { rootSchemaName: "Contact" });
                esq.addColumn("Id");
                esq.addColumn("Name");
                esq.getEntityCollection(function(result){
                    if (result.success){
                        var items = {};
                        result.collection.each(function(item) {
                            items[item.get("Id")] = { "value": item.get("Id"), "displayValue": item.get("Name") };
                        }, this);
                    }
                    var list = this.get("ContactList");
                    list.loadAll(items);
                }, this);
            },
            ownerInputBoxHandler: function(tag, data){
				var autoIds = this.getSelectedItems();
				var selectedContact = data.Owner.value;
                if (Terrasoft.MessageBoxButtons.OK.returnCode === tag){
                    if (Ext.isEmpty(selectedContact)){
                        this.showInformationDialog("Field is required", function(){
                            this.showOwnerInfo();
                        });
                    } else {
                        this.updateAccount(function(context, result){}, autoIds, selectedContact);
                    }
                }
            }
		}
	};
});

You will be able to select an owner from contacts:

and the selected records will be updated properly.

 

Best regards,

Oscar

Hi Kavian,

 

The code below will do the trick:

define("AccountSectionV2", [], function() {
	return {
		entitySchemaName: "Account",
		details: /**SCHEMA_DETAILS*/{}/**SCHEMA_DETAILS*/,
		diff: /**SCHEMA_DIFF*/[]/**SCHEMA_DIFF*/,
		attributes:{},
		methods: {
			updateAccount: function(callback, autoIds, selectedContact){
				var update = Ext.create("Terrasoft.UpdateQuery", {
                            rootSchemaName: "Account"
                        });
				var filters = Terrasoft.createFilterGroup();
				filters.logicalOperation = Terrasoft.LogicalOperatorType.OR;
				autoIds.forEach(function(item) {
					var accountIdFilter = update.createColumnFilterWithParameter(Terrasoft.ComparisonType.EQUAL, "Id", item);
					filters.add("AccountIdFilter" + item, accountIdFilter);
				}, this);
				update.filters.add(filters);
				update.setParameterValue("Owner", selectedContact, Terrasoft.DataValueType.LOOKUP);
				update.execute(function(result) {
					callback.call(this, result);
				}, this);
			},
			getSectionActions: function() {
				var actionMenuItems = this.callParent(arguments);
				actionMenuItems.addItem(this.getButtonMenuItem({
					"Caption": {bindTo: "Resources.Strings.MultiplyChangeAction"},
					"Click": {bindTo: "showOwnerInfo"}
				}));
				return actionMenuItems;
			},
			showOwnerInfo: function() {
                var caption = "Select an owner";
                var ContactList;
                this.set("ContactList", new Terrasoft.Collection());
                var controls = {
                    "Owner": {
                        dataValueType: Terrasoft.DataValueType.ENUM,
                        isRequired: true,
                        caption: "Owner",
                        value: {
                            bindTo: "Contact"
                        },
                        customConfig: {
                            list: {
                                bindTo: "ContactList"
                            },
                            prepareList: {
                                bindTo: "onPrepareContactList"
                            }
                        }
                    }
                };
                var ownerInputBoxHandler = this.ownerInputBoxHandler.bind(this);
                Terrasoft.utils.inputBox(caption, ownerInputBoxHandler, [
					{
						className: "Terrasoft.Button",
						caption: "ASSIGN",
						returnCode: "ok"
					}, "cancel"
				], this, controls);
                Terrasoft.each(Terrasoft.MessageBox.controlArray, function(item){
                    item.control.bind(this);
                }, this);
            },
            onPrepareContactList: function(){
                var esq = this.Ext.create("Terrasoft.EntitySchemaQuery", { rootSchemaName: "Contact" });
                esq.addColumn("Id");
                esq.addColumn("Name");
                esq.getEntityCollection(function(result){
                    if (result.success){
                        var items = {};
                        result.collection.each(function(item) {
                            items[item.get("Id")] = { "value": item.get("Id"), "displayValue": item.get("Name") };
                        }, this);
                    }
                    var list = this.get("ContactList");
                    list.loadAll(items);
                }, this);
            },
            ownerInputBoxHandler: function(tag, data){
				var autoIds = this.getSelectedItems();
				var selectedContact = data.Owner.value;
                if (Terrasoft.MessageBoxButtons.OK.returnCode === tag){
                    if (Ext.isEmpty(selectedContact)){
                        this.showInformationDialog("Field is required", function(){
                            this.showOwnerInfo();
                        });
                    } else {
                        this.updateAccount(function(context, result){}, autoIds, selectedContact);
                    }
                }
            }
		}
	};
});

You will be able to select an owner from contacts:

and the selected records will be updated properly.

 

Best regards,

Oscar

Oscar Dylan,

 

Thanks, the solution works perfectly.

Oleg Drobina,

Hi, 

The code works very well. I however need to display the list as a modal pop up instead of drop down. Could you please let me know what changes need to be done or point me to resources?

Hi 

how I could modify the code (onPrepareContactList) to add a filter to the contact list (only display who are users) !

Oleg Drobina,

Show all comments