0

I build a lightning quick action component to new a record,and carry a few fields value in the quick Action button record page.After checked and make sure I get the value from the background.component.set,and component.get work just fine. Here's the problem,I click the quick action button and those lightning:inputfield did carry the default value,but after click that close icon and open it again,the default value disappear.When open it Second time,I use component.find.get those inputfield auraid and console print it did get the value.Somehow it just not showing.I don't know how to deal with this.Somebody help me!

Cmp:

<aura:component implements="lightning:actionOverride,lightning:hasPageReference,flexipage:availableForRecordHome,force:hasSObjectName,force:lightningQuickActionWithoutHeader,force:hasRecordId" access="global" controller="CorrectiveMeasures8DCmpCtr">
<aura:attribute name="activeSections" type="List" default="['A','B','C']" />
<aura:attribute name="corrImprove" type="List" />
<aura:attribute name="avoidRep" type="List" />
<aura:attribute name="thisWeekSummaryListHeight" type="String" />
<aura:attribute name="CompanyName" type="String" />
<aura:attribute name="ContactName" type="String" />
<aura:attribute name="Department" type="String" />
<aura:attribute name="pageStatus" type="String" />
<aura:attribute name="ProductType" type="String" />
<aura:attribute name="IsUserd8D" type="String" />
<aura:attribute name="AccountReason" type="String" />
<aura:attribute name="ResponsibleDepartment" type="String" />
<aura:attribute name="DealResult" type="String" />
<aura:attribute name="CaseDealSolution" type="String" />
<aura:attribute name="BaseAnalysis" type="String" />
<aura:attribute name="Bussiness" type="String" />
<ltng:require styles="{!$Resource.popupCSS}" />
<aura:handler name="init" value="{!this}" action="{!c.doInit}"/>

<lightning:accordion allowMultipleSectionsOpen="true" onsectiontoggle="{! c.handleSectionToggle }"
    activeSectionName="{! v.activeSections }"> 
<lightning:recordEditForm aura:id="measure8DForm"  objectApiName="CorrectiveMeasures8D__c" onsuccess="{!c.onRecordSuccess}" >
        <lightning:accordionSection name="B" label="{!$Label.c.CorrectiveMeasures8DSecondPART}">
            <div class="slds-grid slds-wrap">
                <div class="slds-col slds-size_1-of-2">
                    <lightning:inputField fieldName="ResonType__c" aura:id="ResonType__c"/>
                </div>
                <div class="slds-col slds-size_1-of-2">
                    <lightning:inputField fieldName="ProRetRea__c" aura:id="ProRetRea__c" value="{!v.AccountReason}"/>
                </div>
                <div class="slds-col slds-size_1-of-2">
                    <lightning:inputField fieldName="BussinesDep__c" aura:id="BussinesDep__c" disabled="true" value="{!v.Bussiness}" />
                </div>
                <div class="slds-col slds-size_1-of-2">
                    <lightning:inputField fieldName="ResponseDep__c" aura:id="ResponseDep__c" value="{!v.ResponsibleDepartment}"/>
                </div>
                <div class="slds-col slds-size_1-of-2">
                    <lightning:inputField fieldName="HandleResult__c" aura:id="HandleResult__c" value="{!v.DealResult}"/>
                </div>
                <div class="slds-col slds-size_1-of-2">
                    <lightning:inputField fieldName="CusHandleSit__c" aura:id="CusHandleSit__c" value="{!v.CaseDealSolution}"/>
                </div>
            </div>
        </lightning:accordionSection>


</lightning:recordEditForm>
</lightning:accordion>
        <div style="text-align: right;border-bottom-right-radius: .25rem;
        border-bottom-left-radius: .25rem;padding: .75rem 1rem;" >                
            <lightning:button variant="neutral" label="Cancel" onclick="{!c.cancelDialog}"/>
            <lightning:button variant="brand" label="Save" onclick="{!c.validation}" />
        </div >

Controller:

({   
doInit : function(component, event, helper) {
    console.log('doInit: '+component.get("v.recordId"));
            var recordTypeId = component.get("v.recordId");
            var action = component.get("c.getPRDInitRecord");
            action.setParams({
                  "recId": recordTypeId
                });
            action.setCallback(this, function(response) {
                 var result = response.getReturnValue();
                 console.log('RootCauseAnalysis__c: '+result.BaseAnalysis__c);
                 console.log('ProRetRea__c: '+result.AccountReason__c);
                 console.log('BussinesDep__c: '+result.Bussiness);
                 console.log('ResponseDep__c: '+result.ResponsibleDepartment__c);
                 console.log('HandleResult__c: '+result.DealResult__c);
                 console.log('CusHandleSit__c: '+result.CaseDealSolution__c);
                 component.set("v.CompanyName", result.CompanyName);
                 component.set("v.ContactName",result.ContactName);
                 component.set("v.Department",result.Department);
                 component.set("v.ProductType",result.ProductType);
                 component.set("v.IsUserd8D",result.IsUserd8D);

                 component.set("v.AccountReason",result.AccountReason__c);
                 console.log('ProRetRea__c的值为: '+component.find("ProRetRea__c").get("v.value"));
                 console.log('AccountReason的值为: '+component.get("v.AccountReason"));

                 console.log('开始find&set初始值!');
                 component.find("RootCauseAnalysis__c").set("v.value",result.BaseAnalysis__c);
                 component.find("ProRetRea__c").set("v.value",result.AccountReason__c);
                 component.find("BussinesDep__c").set("v.value",result.Bussiness);
                 component.find("ResponseDep__c").set("v.value",result.ResponsibleDepartment__c);
                 component.find("HandleResult__c").set("v.value",result.DealResult__c);
                 component.find("CusHandleSit__c").set("v.value",result.CaseDealSolution__c);
                 console.log('RootCauseAnalysis__c的值为: '+component.find("RootCauseAnalysis__c").get("v.value",result.BaseAnalysis__c));
                 console.log('ProRetRea__c的值为: '+component.find("ProRetRea__c").get("v.value"));
                 console.log('BussinesDep__c的值为: '+component.find("BussinesDep__c").get("v.value"));
                 console.log('ResponseDep__c的值为: '+component.find("ResponseDep__c").get("v.value"));
                 console.log('HandleResult__c的值为: '+component.find("HandleResult__c").get("v.value"));
                 console.log('CusHandleSit__c的值为: '+component.find("CusHandleSit__c").get("v.value"));
            });
            $A.enqueueAction(action);



},

cancelDialog : function(component, helper) {
    if (component.get("v.recordId")!=""&&component.get("v.recordId")!=null) {

    var dismissActionPanel = $A.get("e.force:closeQuickAction");
    dismissActionPanel.fire();
    }else{
        var homeEvt = $A.get("e.force:navigateToObjectHome");
        homeEvt.setParams({
            "scope": "Fixed_Product_Request__c"
        });
        homeEvt.fire();
    }
    },
handleSectionToggle : function (cmp, event) {
    var openSections = event.getParam('openSections');

    if (openSections.length === 0) {
        cmp.set('v.activeSectionsMessage', "All sections are closed");
    } else {
        cmp.set('v.activeSectionsMessage', "Open sections: " + openSections.join(', '));
    }
},

getPart : function (component, event) {
    var protype = component.find("Primary_Part__c").get("v.value");
    component.set("v.primaryPart", protype);
    console.log('当前primaryPart的值为: '+component.get('v.primaryPart'));
},


onRecordSuccess: function(component, event, helper) {
  //navigate to new record on successful save
    $A.get('e.force:refreshView').fire();
    var payload = event.getParams().response;
    console.log('新建的Id: '+payload.id);
    var measure8DImp = component.get("v.corrImprove");
    var measure8DRep = component.get("v.avoidRep");
        //纠正措施保存
        var action = component.get("c.getUpSertMeasure8D");
        action.setParams({
                            "newmeasure8D": measure8DImp,
                            "recId": payload.id
                        });
        console.log('set参数完毕');
        action.setCallback(this, function(resp) {
            var respData = resp.getReturnValue();
            console.log('respData'+respData);
        });
        $A.enqueueAction(action);
        //预防措施保存
        var action1 = component.get("c.getUpSertRepMeasure8D");
        action1.setParams({
                            "newmeasure8D": measure8DRep,
                            "recId": payload.id
                        });
        console.log('set参数完毕');
        action1.setCallback(this, function(resp) {
            var respData = resp.getReturnValue();
            console.log('respData: '+respData);
        });
        $A.enqueueAction(action1);

    var resultsToast = $A.get("e.force:showToast");
            resultsToast.setParams({
                 "title": "创建成功!",
                 "type": "success",
            });
             resultsToast.fire();
    window.location.reload();
    var navEvt = $A.get("e.force:navigateToSObject");
    navEvt.setParams({
        "recordId": event.getParam("response").id,
        "slideDevName": "detail"
    });
    navEvt.fire();
},
validation : function (component,event,helper) {
    document.getElementById("ImproveId").style.display='none';
    document.getElementById("avoidId").style.display='none';
    console.error('Validation!');
    console.log('ProRetRea__c的值为: '+component.find("ProRetRea__c").get("v.value"));
    console.log('BussinesDep__c的值为: '+component.find("BussinesDep__c").get("v.value"));
    console.log('ResponseDep__c的值为: '+component.find("ResponseDep__c").get("v.value"));
    console.log('HandleResult__c的值为: '+component.find("HandleResult__c").get("v.value"));
    console.log('CusHandleSit__c的值为: '+component.find("CusHandleSit__c").get("v.value"));
    console.log('准备执行保存方法!');
    if (component.get("v.IsUserd8D")==true) {
        helper.SaveRecord(component);
    }else{
        var dismissActionPanel = $A.get("e.force:closeQuickAction");
        dismissActionPanel.fire();
        var toastEvent = $A.get("e.force:showToast");
        toastEvent.setParams({
            "title": "启动8D分析失败!",
            "message": "[是否使用8D分析]为否!",
            "type" : "error"
        });
        toastEvent.fire();
    }
}
})

Helper:

({
SaveRecord : function (component, event ,helper) { 
    var recordId = component.get("v.recordId");
    var measure8DImp = component.get("v.corrImprove");
    var measure8DRep = component.get("v.avoidRep");
    console.log(measure8DImp.length);
    var flagsummary1 = false;
    var flagsummary2 = false;
    if(measure8DImp.length > 0){
        console.log('進入measure8DImpif');
        for(var i=0;i<measure8DImp.length;i++){
            var sobItem = measure8DImp[i];
            if(sobItem.MeasuresD__c==''||sobItem.MeasuresD__c==null||sobItem.MeasuresD__c==undefined){
                    flagsummary1 = true;
            }
        }
    }
    if(measure8DRep.length > 0){
        console.log('進入measure8DRepif');
        for(var i=0;i<measure8DRep.length;i++){
            var sobItem = measure8DRep[i];
            if(sobItem.Precaution__c==''||sobItem.Precaution__c==null||sobItem.Precaution__c==undefined){
                    flagsummary2 = true;
            }
        }
    }
    console.log('flagsummary1: '+flagsummary1);
    if (flagsummary1 == false && flagsummary2 == false ) {
        component.find("measure8DForm").submit();
        console.log('准备保存!!');

    }else{
        console.log('进入else');
            if (flagsummary1==true) {
                console.log('显示措施描述');
                document.getElementById("ImproveId").style.display='block';
            }
            if (flagsummary2==true) {
                console.log('显示改进描述');
                document.getElementById("avoidId").style.display='block';
            }

        }

    }
})

class:

public class CorrectiveMeasures8DCmpCtr {

@AuraEnabled
public static Map<String,String> getCaseInitRecord(String recId){
    System.debug('recId: '+recId);
    Map<String,String> respData = new Map<String,String>();
    Case caseObj = [SELECT AccountId, Account.Name, Contact.Name, Contact.Department, Id, ContactId FROM Case WHERE Id = :recId];
     respData.put('CompanyName', caseObj.Account.Name);
     respData.put('ContactName', caseObj.Contact.Name);
     respData.put('Department', caseObj.Contact.Department);
     System.debug('CompanyName: '+ caseObj.Account.Name);
     System.debug('ContactName: '+ caseObj.Contact.Name);
     System.debug('Department: '+ caseObj.Contact.Department);
     return respData;
}
//同步客退品明细字段
// @AuraEnabled
// public static String synProReturnRecord(String recId,String proRetRea,String bussinesDep,String responseDep,String handleResult,String cusHandleSit,String rootCauseAnalysis,String groupLeader){
//     String returnValue = 'SUCCESS';
//     System.debug('recId: '+recId);
//     System.debug('proRetRea: '+proRetRea);
//     System.debug('bussinesDep: '+bussinesDep);
//     System.debug('responseDep: '+responseDep);
//     System.debug('handleResult: '+handleResult);
//     System.debug('cusHandleSit: '+cusHandleSit);
//     System.debug('rootCauseAnalysis: '+rootCauseAnalysis);
//     System.debug('groupLeader: '+groupLeader);
//     ProductReturnDetail__c productReturnObj = [SELECT AccountReason__c, Bussiness__c, AccountReturnAnalyze__c, ResponsibleDepartment__c, DealResult__c, Id, CaseDealSolution__c,BaseAnalysis__c,AccountQuantitiesManager__c FROM ProductReturnDetail__c WHERE Id = :recId];
//     productReturnObj.AccountReason__c = proRetRea;
//     productReturnObj.Bussiness__c = bussinesDep;
//     productReturnObj.ResponsibleDepartment__c = responseDep;
//     productReturnObj.DealResult__c = handleResult;
//     productReturnObj.CaseDealSolution__c = cusHandleSit;
//     productReturnObj.AccountReturnAnalyze__c = rootCauseAnalysis;
//     productReturnObj.AccountQuantitiesManager__c = groupLeader;
//     try{
//         Update productReturnObj;
//     }catch(DmlException e){
//         returnValue = e.getMessage();
//     }
//     System.debug('returnValue: '+returnValue);
//     return returnValue;
// }

@AuraEnabled
public static Map<String,Object> getPRDInitRecord(String recId){
    System.debug('recId: '+recId);
    Map<String,Object> respData = new Map<String,Object>();
    ProductReturnDetail__c productReturnDetail = [SELECT Id, Case__c,IsUserd8D__c, ProductModel__r.Name, Case__r.Account.Name, Case__r.Contact.Name, Case__r.Contact.Department 
                                                    ,AccountReason__c,Bussiness__c,AccountReturnAnalyze__c,ResponsibleDepartment__c,DealResult__c
                                                    ,CaseDealSolution__c,BaseAnalysis__c 
                                                        FROM ProductReturnDetail__c WHERE Id = :recId];
    respData.put('CompanyName', productReturnDetail.Case__r.Account.Name);
    respData.put('ContactName', productReturnDetail.Case__r.Contact.Name);
    respData.put('Department', productReturnDetail.Case__r.Contact.Department);
    respData.put('ProductType', productReturnDetail.ProductModel__r.Name);
    respData.put('Bussiness', productReturnDetail.Bussiness__c);
    respData.put('IsUserd8D', productReturnDetail.IsUserd8D__c);
    respData.put('AccountReason__c', productReturnDetail.AccountReason__c);
    respData.put('Bussiness__c', productReturnDetail.Bussiness__c);
    respData.put('ResponsibleDepartment__c', productReturnDetail.ResponsibleDepartment__c);
    respData.put('DealResult__c', productReturnDetail.DealResult__c);
    respData.put('CaseDealSolution__c', productReturnDetail.CaseDealSolution__c);
    respData.put('BaseAnalysis__c', productReturnDetail.AccountReturnAnalyze__c);
    System.debug('CompanyName: '+ productReturnDetail.Case__r.Account.Name);
    System.debug('ContactName: '+ productReturnDetail.Case__r.Contact.Name);
    System.debug('Department: '+ productReturnDetail.Case__r.Contact.Department);
    System.debug('ProductType: '+ productReturnDetail.ProductModel__r.Name);
    System.debug('Bussiness__c: '+ productReturnDetail.Bussiness__c);
    return respData;
}

@AuraEnabled
public static Map<String,Object> getInitData(String recId) {
    Map<String,Object> respData = new Map<String,Object>();
    //获取纠正与改进措施描述
    List<Measure8D__c> measure8DList = [SELECT Id, Name, MeasuresD__c, ExecutorD__c, PreDateD__c, ISCorrection_Improvement__c, Precaution__c, Precaution_Executive__c, Precaution_Scheduled_Date__c, Measure8DName__c 
                        FROM Measure8D__c WHERE Measure8DName__c = :recId AND ISCorrection_Improvement__c = true];


     //获取为避免重复发生类似问题的预防措施
    List<Measure8D__c> measure8DPrecautionList = [SELECT Id, Name, MeasuresD__c, ExecutorD__c, PreDateD__c, ISCorrection_Improvement__c, Precaution__c, Precaution_Executive__c, Precaution_Scheduled_Date__c, Measure8DName__c 
                        FROM Measure8D__c WHERE Measure8DName__c = :recId AND ISCorrection_Improvement__c = false];
    respData.put('corrImprove', measure8DList);
    respData.put('avoidRep', measure8DPrecautionList);
    return respData;
}
@AuraEnabled
public static Map<String,String> getFieldLabel(String sobjectName){
   Map<String,String> returnMap = new Map<String,String>();
   Map<String, Schema.SObjectField> schemaFieldMap = Schema.SObjectType.CorrectiveMeasures8D__c.fields.getMap();
   for (String fieldAPIName: schemaFieldMap.keySet()) {
    Schema.SObjectField F = schemaFieldMap.get(fieldAPIName);
    Schema.DescribeFieldResult R = F.getDescribe();
    returnMap.put(fieldAPIName,R.getLabel());
   }
    return returnMap;
}

/*
*Measure8D行项目刪除
*/
@AuraEnabled
public static String getDeleteMeasure8D(String itemId){
    String deleteResult = 'SUCCESS';
    try{
        Delete new Measure8D__c(Id=itemId);
    }catch(DmlException e){
        deleteResult = e.getMessage();
    }
    return deleteResult;
}

/*
*Measure8D改进行项目保存
*/
@AuraEnabled
public static String getUpSertMeasure8D(List<Measure8D__c> newmeasure8D,String recId){
    String upsertResult = 'SUCCESS';
    System.debug('recordId: '+recId);
    System.debug('List<Measure8D__c>: '+newmeasure8D);
    //新增的Measure8D__c
    List<Measure8D__c> newList = new List<Measure8D__c>();
    //之前填的Measure8D__c
    List<Measure8D__c> oldList = new List<Measure8D__c>();
    for (Measure8D__c mea8d:newmeasure8D ) {

    //  try{
        System.debug('Measure8D__c: '+mea8d.Id);
        if (String.isEmpty(mea8d.Id)) {
            newList.add(mea8d);
        }else{
            oldList.add(mea8d);
        }
    //      Upsert mea8d;
    // }catch(DmlException e){
    //  upsertResult = e.getMessage();
    // }
    //  return upsertResult;
    }
    if(!oldList.isEmpty()){
        Update oldList;//如果是以前添加的,进行更新
    }
    if(!newList.isEmpty()){
        for (Measure8D__c mea8d:newList) {
            mea8d.Measure8DName__c = recId;
            System.debug(mea8d.Measure8DName__c);
            System.debug('1: '+mea8d);
            Insert mea8d;
            System.debug('2: '+mea8d);
        }

    }
    return upsertResult;
}

/*
*Measure8D预防行项目保存
*/
@AuraEnabled
public static String getUpSertRepMeasure8D(List<Measure8D__c> newmeasure8D,String recId){
    String upsertResult = 'SUCCESS';
    System.debug('recordId: '+recId);
    System.debug('List<Measure8D__c>: '+newmeasure8D);
    //新增的Measure8D__c
    List<Measure8D__c> newList = new List<Measure8D__c>();
    //之前填的Measure8D__c
    List<Measure8D__c> oldList = new List<Measure8D__c>();
    for (Measure8D__c mea8d:newmeasure8D ) {

    //  try{
        System.debug('Measure8D__c: '+mea8d.Id);
        if (String.isEmpty(mea8d.Id)) {
            newList.add(mea8d);
        }else{
            oldList.add(mea8d);
        }
    //      Upsert mea8d;
    // }catch(DmlException e){
    //  upsertResult = e.getMessage();
    // }
    //  return upsertResult;
    }
    if(!oldList.isEmpty()){
        Update oldList;//如果是以前添加的,进行更新
    }
    if(!newList.isEmpty()){
        for (Measure8D__c mea8d:newList) {
            mea8d.Measure8DName__c = recId;
            mea8d.ISCorrection_Improvement__c = false;
            System.debug(mea8d.Measure8DName__c);
            System.debug('1: '+mea8d);
            Insert mea8d;
            System.debug('2: '+mea8d);
        }

    }
    return upsertResult;
}

}

  • Without seeing your code, it would be hard to diagnose the problem. Would you mind making an edit to include your code? – sfdcfox Apr 12 at 2:16
  • @sfdcfox I have added my code! Thanks for help – J.Who Apr 12 at 3:52
  • All the picklist type predefined value have this situation – J.Who Apr 15 at 2:31

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.