You need to sign in to do that
Don't have an account?
Stanley Ye 18
component.find().get('v.value') return null
Just created a form as below:
I gave the aura:id to the 'Status__c' field
<lightning:recordEditForm aura:id="recordEditForm" recordId="a4p0k000001c8peAAA" objectApiName="ClientProgramEnrolment__c">
<lightning:inputField fieldName="Status__c" aura:id="cpe_status_test"/>
<lightning:inputField fieldName="StatusChangeReason__c"/>
<lightning:inputField fieldName="AccommodationSettingAfterCessation__c"/>
<lightning:inputField fieldName="MainReasonForCessation__c"/><br/>
</lightning:recordEditForm>
in the js controller:
I used the below command to retrieve the value of the 'Status__c' field:
component.find('cpe_status_test').get('v.value')
Howeve, in the console log, I see it returned 'undefined'
To investigate further, I tried below:
component.find('cpe_status_test') - return '{addValueHandler: ƒ, addValueProvider: ƒ, destroy: ƒ, getGlobalId: ƒ, getLocalId: ƒ, …}'
component.find('cpe_status_test').getGlobalId() - return '13:0'
component.find('cpe_status_test').getLocalId() - return 'cpe_status_test' ;
It seems it does return the element but why get('v.value') doesn't work properly?
Thanks
I gave the aura:id to the 'Status__c' field
<lightning:recordEditForm aura:id="recordEditForm" recordId="a4p0k000001c8peAAA" objectApiName="ClientProgramEnrolment__c">
<lightning:inputField fieldName="Status__c" aura:id="cpe_status_test"/>
<lightning:inputField fieldName="StatusChangeReason__c"/>
<lightning:inputField fieldName="AccommodationSettingAfterCessation__c"/>
<lightning:inputField fieldName="MainReasonForCessation__c"/><br/>
</lightning:recordEditForm>
in the js controller:
I used the below command to retrieve the value of the 'Status__c' field:
component.find('cpe_status_test').get('v.value')
Howeve, in the console log, I see it returned 'undefined'
To investigate further, I tried below:
component.find('cpe_status_test') - return '{addValueHandler: ƒ, addValueProvider: ƒ, destroy: ƒ, getGlobalId: ƒ, getLocalId: ƒ, …}'
component.find('cpe_status_test').getGlobalId() - return '13:0'
component.find('cpe_status_test').getLocalId() - return 'cpe_status_test' ;
It seems it does return the element but why get('v.value') doesn't work properly?
Thanks
I think from the record form in the component intialization the fields will not be load in the form.so it's give the Undefined error.
So i will suggest you to use the Force:RecordUpdate in above the record form like below to fetch that record value. And call the doInit once the record is loaded in the force:recordData.
<aura:attribute name="ClientProgRec" type="Object" />
<aura:attribute type="Object" name="record"/>
<force:recordData aura:id="recordLoader"
recordId="a4p0k000001c8peAAA"
fields="Id, Status__c"
targetRecord="{!v.record}"
targetError="{!v.recordError}"
targetFields="{!v.ClientProgRec}"
recordUpdated="{!c.doInit}" />
<lightning:recordEditForm aura:id="recordEditForm" recordId="a4p0k000001c8peAAA" objectApiName="ClientProgramEnrolment__c">
<lightning:inputField fieldName="Status__c" aura:id="cpe_status_test"/>
<lightning:inputField fieldName="StatusChangeReason__c"/>
<lightning:inputField fieldName="AccommodationSettingAfterCessation__c"/>
<lightning:inputField fieldName="MainReasonForCessation__c"/><br/>
</lightning:recordEditForm>
Now in the doInit method you can get the Value for that
doInit : function(component, event, helper) {
var cpeStatus = component.get("v.ClientProgRec").Status__c;
console.log('@@@ cpeStatus ==> ' + cpeStatus);
}
Can you please Let me know if it helps or not!!!
If it helps don't forget to mark this as a best answer!!!
Thanks,
Maharajan.C
All Answers
When you are getting this value in Js Controller at button click or in any doInit method?
How you are calling the component ..You can't able to call the Lightning record edit form from the .app
Supports only Lightning Experience, Lightning Communities, Salesforce Mobile App .. Add to the record page and try
Component:
<aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
Js Controller:
doInit : function(component, event, helper) {
helper.getCPEList(component); (from this helper method)
helper.getServiceContractMap(component); // Service Contract with 'Incorporated' Change Requests
helper.getServiceContractLineList(component); // Service Contract Line and Related Service Tasks
},
<apex:page Controller="LightningDischargeProcessController" sidebar="true" docType="html-5.0">
<apex:includeLightning />
<script>
//var contactId = "{!$CurrentPage.parameters.id}";
$Lightning.use("c:LightningDischargeProcessApp", function() {
$Lightning.createComponent("c:LightningDischargeProcess",
{"contactId" : ""}, //{ "contactId" : contactId },
"lightning-discharge",
function(cmp) {
//console.log('****** vf page contact Id: ' + contactId);
//console.log('****** vf page console log');
});
});
</script>
<div id="lightning-discharge" />
</apex:page>
Supports only Lightning Experience, Lightning Communities, Salesforce Mobile App .. Add to the record page and try
({
doInit : function(component, event, helper) {
helper.getCPEList(component);
}
})
Helper:
({
getCPEList : function(component) {
var paramId = this.getUrlParameter('id');
var action = component.get('c.findCPEToDischarge');
var params = {"contactId" : paramId};
//var params = {"contactId" : component.get('v.contactId')};
action.setParams(params);
action.setCallback(this, function(response){
var state = response.getState();
if(state = "SUCCESS"){
component.set('v.li_cpeToDischarge', response.getReturnValue());
component.set('v.contactId', paramId);
this.getDischargeCase(component);
var findVal = component.find('cpe_status_test');
if($A.util.isArray(findVal)){
findVal.forEach(val =>{
console.log(val);
console.log(val.getGlobalId());
console.log(val.getLocalId());
console.log(val.get('v.value')); // return undefined
})
}
else{
console.log(findVal);
console.log(findVal.getGlobalId());
console.log(findVal.getLocalId());
console.log(findVal.get('v.value'));
}
}
});
$A.enqueueAction(action);
},
})
In Console log:
{addValueHandler: ƒ, addValueProvider: ƒ, destroy: ƒ, getGlobalId: ƒ, getLocalId: ƒ, …}
LightningDischargeProcess.js:69 13:0
LightningDischargeProcess.js:70 cpe_status_test
LightningDischargeProcess.js:71 undefined
I think from the record form in the component intialization the fields will not be load in the form.so it's give the Undefined error.
So i will suggest you to use the Force:RecordUpdate in above the record form like below to fetch that record value. And call the doInit once the record is loaded in the force:recordData.
<aura:attribute name="ClientProgRec" type="Object" />
<aura:attribute type="Object" name="record"/>
<force:recordData aura:id="recordLoader"
recordId="a4p0k000001c8peAAA"
fields="Id, Status__c"
targetRecord="{!v.record}"
targetError="{!v.recordError}"
targetFields="{!v.ClientProgRec}"
recordUpdated="{!c.doInit}" />
<lightning:recordEditForm aura:id="recordEditForm" recordId="a4p0k000001c8peAAA" objectApiName="ClientProgramEnrolment__c">
<lightning:inputField fieldName="Status__c" aura:id="cpe_status_test"/>
<lightning:inputField fieldName="StatusChangeReason__c"/>
<lightning:inputField fieldName="AccommodationSettingAfterCessation__c"/>
<lightning:inputField fieldName="MainReasonForCessation__c"/><br/>
</lightning:recordEditForm>
Now in the doInit method you can get the Value for that
doInit : function(component, event, helper) {
var cpeStatus = component.get("v.ClientProgRec").Status__c;
console.log('@@@ cpeStatus ==> ' + cpeStatus);
}
Can you please Let me know if it helps or not!!!
If it helps don't forget to mark this as a best answer!!!
Thanks,
Maharajan.C
Appreciate it!