0

I'm trying to use <lightning:recordEditForm> in a Lightning Component as an Action Override using lightning:actionOverride interface.

I've overridden the Contact New button with this Lightning Component. Issue is, it opens the form, but it won't pre-populate the AccountId from the source record (as I'm coming from Contact Related List of Account record).

Strange thing that happened was, if I use same code on any other Object (which has a Record Type enabled on it), then I can see in the URL an additionalParams parameter with the parent record's ID value.

So for an object without a Record type, when overridding Standard New action, it does not generate any additionalParams parameter with source record id.

Is this a bug?

And do anyone have a way to make the component work and read the source record value, in actionOverride?

My Lightning Component Code (below):

ContactFormOverride.cmp

<aura:component implements="force:hasRecordId,lightning:actionOverride">
    <aura:attribute name="disabled" type="Boolean" default="false" />
    <aura:attribute name="saved" type="Boolean" default="false" />
    <aura:attribute name="showSpinner" type="Boolean" default="true" />
    <aura:attribute name="recordId" type="String" />

    <div class="slds-card slds-p-around_medium slds-is-relative">
        <aura:if isTrue="{!v.showSpinner}">
            <lightning:spinner />
        </aura:if>
        <aura:if isTrue="{!!v.saved}">
            Record ID: {!v.recordId}<br/>
            <lightning:recordEditForm   onload="{!c.handleLoad}"
                                        onsubmit="{!c.handleSubmit}"
                                        onsuccess="{!c.handleSuccess}"
                                        objectApiName="Contact">
                <!-- the messages component is for error messages -->
                <lightning:messages />

                <lightning:inputField fieldName="FirstName" />
                <lightning:inputField fieldName="LastName" />
                <lightning:inputField fieldName="AccountId" />
                <lightning:inputField fieldName="Birthdate" />
                <div class="slds-m-top_medium">
                    <lightning:button disabled="{!v.disabled}" variant="brand" type="submit" name="save" label="Save" />
                </div>
            </lightning:recordEditForm>
            <aura:set attribute="else">
                <p>Saved! New record id is {!v.recordId}</p>
            </aura:set>
        </aura:if>
    </div>
</aura:component>

ContactFormOverrideController.js

({
    handleLoad: function(cmp, event, helper) {
        cmp.set('v.showSpinner', false);
    },
    handleSubmit: function(cmp, event, helper) {
        cmp.set('v.disabled', true);
        cmp.set('v.showSpinner', true);
    },
    handleError: function(cmp, event, helper) {
        // errors are handled by lightning:inputField and lightning:messages
        // so this just hides the spinner
        cmp.set('v.showSpinner', false);
    },
    handleSuccess: function(cmp, event, helper) {
        var params = event.getParams();
        cmp.set('v.recordId', params.response.id);
        cmp.set('v.showSpinner', false);
        cmp.set('v.saved', true);
    }
})
3
  • What you are trying to do - as getting the parent context from a related list on a overridden new button, you can't. Refer to this answer for details around this behavior.
    – Jayant Das
    Sep 12, 2018 at 13:51
  • damn! I was hoping there is a workaround for this :-|
    – VarunC
    Sep 12, 2018 at 13:54
  • Welcome to the group :) Hopefully the idea makes to the product feature list.
    – Jayant Das
    Sep 12, 2018 at 13:55

0