3

I'm using lightning:inputfield in a lightning:recordeditform for lookup fields - we'll call them Party and Warehouse. The Warehouse lookup has filters on it based on the Account field - Warehouse.Account = Party.Account.

When we're creating a new record, this Party field is prepopulated from an Apex controller. The problem I'm having is that even though the component gets the value for Party prepopulated correctly, the Warehouse filter does not register that we've selected the Party Account, so it returns no results. How do I get this to work with the Warehouse field filters?

Component:

<aura:attribute name="party" type="String" />
    <lightning:inputfield aura:id="orderProduct" name="Party__c" fieldName="Party__c" value="{!v.party}"/>
    <lightning:inputfield aura:id="orderProduct" name="Warehouse__c" fieldName="Warehouse__c"/>

Controller:

    console.log('Initializing New Line...');
    const action = component.get("c.initializeLine");
    action.setParams({
        orderId: orderRecordId
    });
    action.setCallback(this, function(a){
        if (a.getState() == 'SUCCESS') {
            console.log('Return Values: ' + JSON.stringify(a.getReturnValue()));
            helper.setValues(component, a.getReturnValue());
        }else if (a.getState() == 'ERROR'){
            console.log(a.getError());
            $A.log("Errors", a.getError());
        }
    });
    $A.enqueueAction(action);

Helper:

  setValues: function(component, record){
        console.log('Set Values for Record: ' + JSON.stringify(record));     
        component.set("v.price", record.UnitPrice);
        component.set("v.quantity", record.Quantity);
        component.set("v.party", record.party__c);
    }

Apex Controller:

@AuraEnabled

public static OrderItem initializeLine(Id orderId){
        Order o = getOrder(orderId);
        if (o != null){
            OrderItem newLine = new OrderItem();
            newLine.OrderId = o.Id;
            newLine.Party__c = o.Party__c;
            return newLine;
        }
        return null;

}

Filter Criteria: enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.