Question

Prefill multi lookup fields

Hi Community,

I have the following multi lookup fields:

 

I want the one on the right side (InvoiceRecipient) to be prefilled with the value of the one on the left (ContractClient) if there is anything in the one on the left.

 

//multiLookup Feld "ContractClient"
"ContractClient": {
                "caption": {"bindTo": "Resources.Strings.Client"},
                "dataValueType": this.Terrasoft.DataValueType.LOOKUP,
                "multiLookupColumns": ["Account", "Contact"],
                "isRequired": true
},
 
//multiLookup Feld "InvoiceRecipient"
"InvoiceRecipient": {
                "caption": "Invoice recipient",
                "dataValueType": this.Terrasoft.DataValueType.LOOKUP,
                "multiLookupColumns": ["InvoiceRecipientContact", "InvoiceRecipientAccount"],
                "isRequired": true
},

 

A simple this.set("InvoiceRecipient", this.get("ContractClient") ) doesn't work, because the InvoiceRecipient object doesn't exist (undefined).

 



Has anyone been able to solve this problem?

 

Best regards,

Oliver

 

 

Like 0

Like

2 comments

Hello,

I believe that this example will help you with your task.

In there in the method onEntityInitialized and onwards we are setting values for some columns. At that point, you should have a "doesn't exist" error.

Here is the solution:

 

attributes: {
	//multiLookup Feld "Contract"
	"ContractClient": {
		"caption": {"bindTo": "Resources.Strings.Client"},
		"dataValueType": this.Terrasoft.DataValueType.LOOKUP,
		"multiLookupColumns": ["Account", "Contact"],
		"isRequired": true,
		"dependencies": [
			{
				  "columns": ["ContractClient"],
				  "methodName": "onContractClientChange"
			}
		]
 
	},
 
	//multiLookup Feld "InvoiceRecipient"
	"InvoiceRecipient": {
		"caption": {"bindTo": "Resources.Strings.InvoiceRecipient"},
		"dataValueType": this.Terrasoft.DataValueType.LOOKUP,
		"multiLookupColumns": ["InvoiceRecipientContact", "InvoiceRecipientAccount"],
		"isRequired": true
	}
}
 
methods: {
	onContractClientChange: function(argument, field) {
		const contactClient = this.get("ContractClient");
 
		if (!Terrasoft.isEmpty(contactClient)) {
			const invoiceRecipient = {
				column: contactClient.column,
				value: contactClient.value,
				displayValue: contactClient.displayValue
			};
			this.set("InvoiceRecipient", invoiceRecipient);
 
			if(contactClient.column == "Account") {
				this.set("InvoiceRecipientAccount", contactClient);
			}
			if(contactClient.column == "Contact") {
				this.set("InvoiceRecipientContact", contactClient);
			}
		}
	}
}

 

Show all comments