I have added this piece of code to populate a single line of text field with the name from a related lookup. It works fine when you put a value in the lookup but if you clear the value from the look up it throws this error: Cannot read properties of null (reading '0'). I know it is throwing that because the field is null. What do I need to do to this code to make it not execute if the lookup is null?
function planName(executionContext) {
var household = formContext.getAttribute(/si_household/).getValue()[0].id;
var householdEntityType = formContext.getAttribute(/si_household/).getValue()[0].entityType;
var householdName = formContext.getAttribute(/si_household/).getValue()[0].name;
var hhLookup = new Array();
hhLookup[0] = new Object();
hhLookup[0].id = household;
hhLookup[0].entityType = householdEntityType;
hhLookup[0].name = householdName;
formContext.getAttribute(/ah_planname/).setValue(hhLookup[0].name);
}