You need to sign in to do that
Don't have an account?
Gurleen Kaur
Unable to set Component attribute value in Helper class
Hi,
I am facing an issue in assigning attribute value for a component in saveResult method, inside helper class:
Component:
<aura:attribute name="isOwnerDefined" type="String" default=""/>
<force:recordData aura:id="CntctTypeRecordCreator"
targetRecord="{!v.newContact}"
targetFields="{!v.CntctTypeResultFields}"
layoutType="FULL"
mode="EDIT" />
JS Controller :
component.find("CntctTypeRecordCreator").saveRecord($A.getCallback(function(saveResult) {
if(saveResult.state === "SUCCESS" || saveResult.state === "DRAFT"){
for(var key in component.get("v.cntctTypesMap")){
if(component.get("v.selectedOption") == key){
helper.setContactTypeMAppingRec(component,key,saveResult.recordId);
break;
}
}
}))
Helper:
setContactTypeMAppingRec : function(component,mappingName,recordId) {
component.set("v.newCntctMappingField.Contact__c",recordId);
component.set("v.newCntctMappingField.ContactType__c",component.get("v.cntctTypesMap")[mappingName]);
component.set("v.newCntctMappingField.Name",mappingName);
component.find("cnTypeRecordLoader").saveRecord($A.getCallback(function(saveResultContact) {
if(saveResultContact.state === "SUCCESS" || saveResultContact.state === "DRAFT"){
component.set("v.isOwnerDefined",'myTest'); // I have assigned string value to component attribute
console.log('====' + component.get("v.isOwnerDefined")); // But here it returns "undefined"
console.log('Contact Type mapping Saved!!');
}
else if (saveResultContact.state === "INCOMPLETE")
console.log('Server could not be reached. Check your internet connection!');
else if (saveResultContact.state === "ERROR")
console.log('Exception Found!');
else
console.log('Error while loading Current Processor Picklist. Please contact your System Administrator.');
}))
}
Any Help?
I am facing an issue in assigning attribute value for a component in saveResult method, inside helper class:
Component:
<aura:attribute name="isOwnerDefined" type="String" default=""/>
<force:recordData aura:id="CntctTypeRecordCreator"
targetRecord="{!v.newContact}"
targetFields="{!v.CntctTypeResultFields}"
layoutType="FULL"
mode="EDIT" />
JS Controller :
component.find("CntctTypeRecordCreator").saveRecord($A.getCallback(function(saveResult) {
if(saveResult.state === "SUCCESS" || saveResult.state === "DRAFT"){
for(var key in component.get("v.cntctTypesMap")){
if(component.get("v.selectedOption") == key){
helper.setContactTypeMAppingRec(component,key,saveResult.recordId);
break;
}
}
}))
Helper:
setContactTypeMAppingRec : function(component,mappingName,recordId) {
component.set("v.newCntctMappingField.Contact__c",recordId);
component.set("v.newCntctMappingField.ContactType__c",component.get("v.cntctTypesMap")[mappingName]);
component.set("v.newCntctMappingField.Name",mappingName);
component.find("cnTypeRecordLoader").saveRecord($A.getCallback(function(saveResultContact) {
if(saveResultContact.state === "SUCCESS" || saveResultContact.state === "DRAFT"){
component.set("v.isOwnerDefined",'myTest'); // I have assigned string value to component attribute
console.log('====' + component.get("v.isOwnerDefined")); // But here it returns "undefined"
console.log('Contact Type mapping Saved!!');
}
else if (saveResultContact.state === "INCOMPLETE")
console.log('Server could not be reached. Check your internet connection!');
else if (saveResultContact.state === "ERROR")
console.log('Exception Found!');
else
console.log('Error while loading Current Processor Picklist. Please contact your System Administrator.');
}))
}
Any Help?
Try this one, just I have changed single quote to double quote.
component.set("v.isOwnerDefined", "myTest");
Are you getting any errors? Please use Lightning Inspector tool to inpect the value of attritbute.
Thanks,
Gaurav
Skype: gaurav62990
Just a catch here. I tried checking the validity of the component using component.isValid() just before setting attribute component.set("v.isOwnerDefined",'myTest' ) at line 19, the component.isValid() is returning false.
But when I try assigning the component attribute value just on Line 15 it is printing correct value.
So, would you know why the validity of the component is getting lost on Line 19?.
Helper:
setContactTypeMAppingRec : function(component,mappingName,recordId) {
component.set("v.newCntctMappingField.Contact__c",recordId);
component.set("v.newCntctMappingField.ContactType__c",component.get("v.cntctTypesMap")[mappingName]);
component.set("v.newCntctMappingField.Name",mappingName);
Line 15==> /*component.set("v.isOwnerDefined",'myTest'); // I have assigned string value to component attribute
console.log('====' + component.get("v.isOwnerDefined")); // Here it prints the correct value
*/
component.find("cnTypeRecordLoader").saveRecord($A.getCallback(function(saveResultContact) {
if(saveResultContact.state === "SUCCESS" || saveResultContact.state === "DRAFT"){
Line 19==> if(component.isValid()){ // It returns "False "
component.set("v.isOwnerDefined",'myTest');
console.log('====' + component.get("v.isOwnerDefined"));
}
console.log('Contact Type mapping Saved!!');
}
else if (saveResultContact.state === "INCOMPLETE")
console.log('Server could not be reached. Check your internet connection!');
else if (saveResultContact.state === "ERROR")
console.log('Exception Found!');
else
console.log('Error while loading Current Processor Picklist. Please contact your System Administrator.');
}))
}
Please read component validity resource of Salesforce, this might provide you some insight.
https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/js_cmp_isvalid.htm
Thanks,
Gaurav
Yes, that might be the issue over here. You can write trigger on parent object to perform this (Classic model never fails to work)
For more details, please go through this link (http://sfdcmonkey.com/2017/04/30/add-multiple-child-records-lightning-component/)
Thanks,
Gaurav
skype: gaurav62990
- Update Component with *component.set("v.isOwnerDefined",'myTest');
- Call another method in Helper.JS to update / create child record.
- Then check component validity and if valid show the result on page.
I am not sure will this work, but give a try.Thanks,
Gaurav