• sumit kumar 49
  • NEWBIE
  • 0 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies
I have a record edit form that works for me, but "rarely" works for another user (I'm logging in as that user to test this) -- but here's the kicker -- *until* they go do other stuff and come back later.

The lightning component consists of a lightning:recordEditForm that has several fields including about 4 lookup fields (Account, Contact, managed obj Vehicle Inventory and managed obj Location). One of the lookups is to a custom object, and gets a default value based on the user's settings. When creating a new record, the default value shows up properly. The record is saved and that location lookup value is in the record -- it's visible in the "Recent items" related list.  But when this user re-opens the record that value isn't there anymore. 

When the value will NOT display on-screen I'm seeing an error 4 times in my Chrome consols: "Cannot read property 'color' of undefined.'  This error occurs *between* the completion of my "init" handler and the start of the RecordEditForm's onload method. The "setDefaultLocation" routine runs correctly when initiating a new record, but does not run (and shouldn't) when displaying an existing record with the value specified.

I've verified that the user has read & edit authority on all fields in the object and can read the target object of the lookup field. And again, if I log off as this user, then log in as this user again (or just go on to other things and come back later), then the lookup field is properly displayed.

I think the full code is too much for the forum, but here are some snippets:

<aura:component implements="flexipage:availableForRecordHome,force:hasRecordId,force:appHostable,lightning:actionOverride"
    controller="RentalAgreementLex">
...
    <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
...
<lightning:recordEditForm recordId="{!v.recordId}" objectApiName="dealer__Rental_Agreements__c"
    aura:id="newrecordform" onsuccess="{!c.recordSaved}" onerror="{!c.recordSaveError}"
    onload="{!c.pageload}">
...
            <lightning:inputField fieldName="Location__c" disabled="{!v.alreadyposted}" aura:id="location"
                required="true" readonly="{!v.alreadyposted}" class="mw_required"/>


Some of the controller code:
/* general page initializations */
    doInit : function(component, event, helper) {
        console.log('doInit');
        // initialize that we're not in the process of posting
        component.set("v.posting", false);
...
        console.log('doInit complete');
    },
    /* initializations when recordeditform is loaded */
    pageload: function(component, event, helper) {
        console.log('pageload');
        let id = component.get("v.recordId");
        console.log(id);
        let sts = (id==null) ? null : component.find("agreement_status").get("v.value");
        if (id==null) {
            sts = 'Open';   // default value
            let stscmp = component.find("agreement_status");
            if (stscmp!=null) stscmp.set("v.value", sts);
            component.set("v.status", sts); // also init record data status
            component.find("deposit_amount").set("v.value",0.00);   // default value
            component.find("excess_miles_charge").set("v.value",0.00);  // default value
            component.set("v.title","New Rental Agreement");
            component.find("totalperdiemtax").set("v.value",0.00);  // default value
            component.find("sales_tax").set("v.value",0.00);    // default value
            component.find("countysalestax").set("v.value",0.00);   // default value
            component.find("citysalestax").set("v.value",0.00); // default value
            component.find("thirdtierrentaltax").set("v.value",0.00);   // default value
        }
        // in doInit: component.set("v.title", name);
        let isopen = sts!='Paid';
        let posting = component.get("v.posting");
        console.log('isopen = ' + isopen);
        // enable/disable buttons based on rental status
        if (!posting && isopen) component.find("submitbutton").set("v.disabled", false);
        if (!posting && id!=null && isopen) component.find("postbutton").set("v.disabled",false);
        let fromaccount = component.get("v.fromaccount");
        if (fromaccount!==null) {
            component.find("account").set("v.value",fromaccount);
            helper.rtvPersonContactId(component, event);
        }
        let fromcontact = component.get("v.fromcontact");
        if (fromcontact!==null) {
            component.find("contact").set("v.value",fromcontact);
            helper.rtvContactsAccountId(component, event);
        }
        if (isopen) component.set("v.alreadyposted", false);
        else component.set("v.alreadyposted", true);
        // set default location
        let c_location = component.find("location");
        let location = null;
        if (c_location!=null) location = c_location.get("v.value");
        if (id==null && location==null) helper.rtvUserDefaultLocation(component, event);
        // initialize running totals
        helper.recalcTotals(component, event);
        console.log('pageLoad complete');
    },