+ Start a Discussion
Jonathan Glass 18Jonathan Glass 18 

Pre-populate fields lightning components

Hi all,

Im currently facing an issue with the "e.force:createRecord" when trying to pre populate some fields from an object to another one. Im using the "defaultFieldValues" and almost every field is populated correctly (Lookup, text,etc) except Currency and Master-Detail.

For your understanding of the issue, when i query the data and show it on the console its shows completly fine ("234" currency field), but at the moment to pre populate it just dont, it keeps the field blank. Also ive tried to: ParseInt, Integer the value, and nothing.
Also, the fuctionallity on Classic mode it working fine, so its not a permision issue (Profile, FLS,etc).

Do you know why is this happenening? Happens to 2 different currency field and also to the master-detail (havent reasearch or even tried anything on this but if you can help also i will appreciate it).

Make sure you are setting the value of the field and please share a code snippet if possible.
Jonathan Glass 18Jonathan Glass 18
Hi Rahul,

As i mention before all other fields are populating just fine, so i belevie im seeting the values ok. Also querying them from my Apex class.

    doInit : function(component, event, helper) {
        var action = component.get("c.getOffers");
            "caseManagementId": component.get("v.recordId")
                if (response.getState() === "SUCCESS"){
                    component.set("{!v.Offers__c}", response.getReturnValue());                                      
                 } else {
                console.log("Failed with state: " + state);
    createPolicy : function (component, event, helper) {

        var createRecordPolicy = $A.get("e.force:createRecord");
        var offerToPass = [];
        var itemList = component.get("v.Offers__c");
        for (var Item in itemList) {            
            if (itemList[Item].checkboxWrapper != undefined && itemList[Item].checkboxWrapper == true ) {
        if (offerToPass.length > 1) {
                "You must select only 1 offer"
        } else if ( offerToPass.length == 0) {
                "You must select at least 1 offer"
          } else {
            console.log("### " + parseInt(offerToPass[0].offer.Modal_Premium__c));
                //Populated fields from the Offer
                "entityApiName": "XLR8_Insurance__c",
                "defaultFieldValues": {
                'Name': offerToPass[0].offer.Name,
                'Product_Type__c' : offerToPass[0].offer.Product_Type__c,
                'Carrier_Provider__c' : offerToPass[0].offer.Carrier_Provider__c, // master detail
                'Modal_Premium__c' : offerToPass[0].offer.Modal_Premium__c, // currency
                'Annualized_Premium__c' : offerToPass[0].offer.Annualized_Premium__c, // currency 
                'Premium_Frequency__c' : offerToPass[0].offer.Premium_Frequency__c,
                'Insured_Risk_Classification__c' : offerToPass[0].offer.Insured_Risk_Classification__c,
                'Co_Insured_Risk_Classification__c' : offerToPass[0].offer.Co_Insured_Risk_Classification__c,
                'Insured_Table_Rating__c' : offerToPass[0].offer.Insured_Table_Rating__c,
                'Co_Insured_Table_Rating__c' : offerToPass[0].offer.Co_Insured_Table_Rating__c,
                //Populated fields from the Case Management
                'Primary_Producer__c' : offerToPass[0].offer.Case_Management__r.Primary_Producer__c,
                'Producer_Type__c' : offerToPass[0].offer.Case_Management__r.Producer_Type__c,
                'Entity__c' : offerToPass[0].offer.Case_Management__r.Entity__c,
                'Name' :offerToPass[0].offer.Case_Management__r.Name,
                'Insured_Name__c' : offerToPass[0].offer.Case_Management__r.Insured_Name__c,
                'Co_Insured_Name__c' : offerToPass[0].offer.Case_Management__r.Co_Insured_Name__c,
                'Servicing_Firm_Entity__c' : offerToPass[0].offer.Case_Management__r.Servicing_Firm_Entity__c,
                'Insured_Tobacco_Class__c' : offerToPass[0].offer.Case_Management__r.Insured_Tobacco_Class__c,
                'Co_Insured_Tobacco_Class__c' : offerToPass[0].offer.Case_Management__r.Co_Insured_Tobacco_Class__c
                recordTypeId: '012G00000010cwMIAQ'



Jonathan Glass 18Jonathan Glass 18
Hi Piyush_soni, i did, the data is coming fine from sf as i can show the value on the console but is it not pre populating.
Alain CabonAlain Cabon

 "defaultFieldValues" and almost every field is populated correctly (Lookup, text,etc) 

... with <force:inputfield> ? this component is only prepulated with the defaultFieldValues. That is IMPOSSIBLE from the controller and so, this component is almost not usable.

My detailed explanation here:

This list of drawbacks of <force:inputfield> is not explained in the documentation (excepted for some types of field (dependant picklist)).

There is no example of a lookup field in the Lightning Components Developer Guide.