I have a web resource for my model driven app. I have two errors. I'll focus on the first one because I don't expect the second error to be resolved here. I essentially have three lookup fields. The first field has a selection of companies. The second and third fields have filtered selections based on the first field. However, whenever I unselect whatever is in the first field an error occurs and reads "TypeError: Cannot read properties of null (reading '0')".
To make matters worse, the selected options in the second and third fields remain static. I.e. whatever was filtered from my first selection remains in the second and third fields regardless of what I select again in the first column.
The handler for the first field's event is onChange for "Sdk.attributeOnChange".
(My other major problem is that the first field has many duplicate options. There's only supposed to be a unique option for each selection).
Any help for pinpointing and resolving the error is greatly appreciated. This is the javascript code for the webresource:
How would I go about attaching a custom view that would filter out the duplicates?
For clarity, the reason why there are duplicates is because each duplicate row contains the associated value for the approvers.
Just to add up @bfujioka ,
Why do you have duplicates in first lookup?
Since it will pick the records you enter in table 'Company'.
You must check if you're allowing duplicates in your system.
Add duplicate detection rules or create and attach a custom view with your requirements
Moveover, disable recent searches from lookup control properties on the form.
Hope this helps
Hi @bfujioka ,
I'll provide a rough idea of how to validate items and clear accordingly based on input
var NameSpace =
{
//OnChange of the first Field
Companies: function(executionContext)
{
var formContext = executionContext.getFormContext();
if(formContext != null || formContext != undefined)
{
if(formContext.getAttribute("cr866_ab_company"))
{
if(formContext.getAttribute("cr866_ab_company") !== null)
{
var company = formContext.getAttribute("cr866_ab_company").getValue();
if(company == null)
{
NameSpace.ClearFields(formContext, ["cr866_secondField", "cr866_thirdField"]);
}
else
{
NameSpace.SetCustomFiltersByCompany(formContext, company);
}
}
}
}
},
ClearFields: function(formContext, ArrayFields)
{
//Use a Loop to clear out the field data from the Form.
},
SetCustomFiltersByCompany(formContext, company)
{
//Set 2nd and 3rd Fields as per 1st Field company
}
}
Here, use NameSpace.Companies() for OnLoad and OnChange of 1st field
Hope this helps
formContext.getAttribute("cr866_ab_company").getValue()[0];
you need to check if the .getValue() returns null before trying to access its [0]
Edit: also if you clear a Lookup and there are other related Lookups, you will also need to clear them in your code.
MS.Ragavendar
27
mmbr1606
14
Super User 2025 Season 1
EE-04041031-0
11