I encounter a problem with the Lookup component. We want to implement a convenient feature for users because they need to select an item from the lookup list and there may be over 30 lookup fields in the Sub List they need to fill in.
The feature behaviour is:
If any lookup in a Sub List only contains one item. Then the item is selected by default and shown to the user in the sub list
The first question for us is whether we don’t know how to count the number of items of a lookup in a Sub List via Expression Editor. The current solution is calling Query Data List API via HTTP Request to get the count but it seems quite complicated for development. Is there any simple way for counting the number of items in a lookup?
The second question is if we want to set a lookup with a default item, this must trigger the Change Value action from any input field of the current row of a sub-list. Is it possible to set the default item of lookups in a sub-list during the page load?
One possible solution would involve disabling the “Add Item” function for a sub list, while implementing a button that triggers the action to add new line to it. For reference, please see the following sample custom codes.
export class CodeInApplication implements CodeInComp {
execute(context: CodeInContext, fieldsValues: any) {
return new Promise((resolve, reject) => {
const params = context.params;
const fieldId = params["varId"];
let list = fieldsValues[fieldId];
if (!list) {
list = [];
}
list.push({ field_1: `Initial value: ${list.length}` });
context.setFieldValue(fieldId, [...list]);
resolve(true);
});
}
requiredFields(params) {
return [params["varId"]];
}
requiredModules() {
return [];
}
description() {
return "Add a row to list";
}
inputParameters() {
return [{
id: "varId",
type: "string",
desc: "Varaible ID of the list"
}] as InputParameter[];
}
}