You need to sign in to do that
Don't have an account?
SF_Monkey
pass recordId to another lightning component using lightning:navigation
I having issues with passing the recordId from acapBtn.cmp to acapChecklist.com.
I have interface lightning:isUrlAddressable on both the component. It is navigating to the right component; however, it is not passing the recordId value to the acapChecklist.cmp.
Thanks!
acapBtn.cmp <lightning:navigation aura:id="navigationService"/> acapBtnController var recordId = component.get("v.recordId"); component.find("navigationService").navigate({ type: "standard__component", attributes: { componentName: "c__acapChecklist" }, state: { recordId: recordId } });
I have interface lightning:isUrlAddressable on both the component. It is navigating to the right component; however, it is not passing the recordId value to the acapChecklist.cmp.
Thanks!
All Answers
https://rajvakati.com/2018/11/13/navigate-to-component-using-lightningnavigation/
GIve me the complete code
You have to read them linke below
acapChecklist.cmp
acapChecklist Controller
acapBtnController
there is alot of unrelated code in. thanks!
c:acapChecklist$controller$init [Cannot read property 'state' of null]
acapChecklist controller acapBtn.cmp
acapBtn controller
Please try this below code and let me know your feedback.
Here is the whole code of both component.
1. FromComponent.cmp
2. FromComponent.controller
3. ToComponent.controller := get the value of PageReference in doInIt method of second component controller.
Please apply and test this code.
--------------------
({
doOrder : function(component, event, helper) {
var pageReference = component.find("navigation");
var pageReferenceNav = {
"type": "standard__component",
"attributes": {
"componentName": "c__Createorder"
},
"state": {
c__beerId: component.get('v.beerId') ,
c__beerName: component.get('v.beerName')
}
};
pageReference.navigate(pageReferenceNav);
}
})
---------------------------------------------------------------------------
({
doInit : function(component, event, helper) {
var pageReference = component.get('v.pageReference');
if(pageReference){
var state = pageReference.state;
component.set('v.beerId', state.c__beerId);
component.find("recordEditor").reloadRecord();
}
component.find("newRecordCreator").getNewRecord(
"Beer_Order__c",
null,
false,
$A.getCallback(function() {
var rec = component.get("v.newRecordObject");
var error = component.get("v.newRecordError");
if(error || (rec === null)) {
console.log("Error initializing record template: " + error);
}
else {
console.log("Record template initialized: " + rec.sobjectType);
}
})
);
},
handleSubmit : function(component, event, helper) {
var beerRecord = component.get('v.simpleRecord');
console.log('beerRecord Price', beerRecord.Price__c);
console.log('beerRecord Tag', beerRecord.Tags__c);
var quantity = component.get('v.beerOrder.Ordered_Quantity__c');
console.log('Ordered price ', quantity);
var totalPrice = parseInt(beerRecord.Price__c)*parseInt(quantity);
console.log(' totalPrice ', totalPrice);
var isValid = helper.validateForm(component, event, helper);
if(component.get("v.beerOrder.Billing_Same_as_Shipping__c")){
component.set('v.beerOrder.Billing_Street__c', component.get('v.beerOrder.Shipping_Street__c'));
component.set('v.beerOrder.Billing_City__c', component.get('v.beerOrder.Shipping_City__c'));
component.set('v.beerOrder.Billing_Country__c', component.get('v.beerOrder.Shipping_Country__c'));
component.set('v.beerOrder.Billing_State__c', component.get('v.beerOrder.Shipping_State__c'));
component.set('v.beerOrder.Billing_Postal_Code__c', component.get('v.beerOrder.Shipping_Postal_Code__c'));
}
if(!isValid)
return;
var userId = $A.get("$SObjectType.CurrentUser.Id");
//alert(userId);
component.set("v.beerOrder.Beer__c", component.get("v.beerId"));
component.set("v.beerOrder.Ordered__c", userId);
component.set("v.beerOrder.Order_Amount__c", parseInt(totalPrice));
component.find("newRecordCreator").saveRecord(function(saveResult) {
if (saveResult.state === "SUCCESS" || saveResult.state === "DRAFT") {
var resultsToast = $A.get("e.force:showToast");
resultsToast.setParams({
"title": "Order Placed",
"message": "Your Order has been successfully placed. " ,
"type" : "success"
});
resultsToast.fire();
helper.updateBeerQty(component, event,quantity, saveResult.recordId);
} else if (saveResult.state === "INCOMPLETE") {
console.log("User is offline, device doesn't support drafts.");
} else if (saveResult.state === "ERROR") {
console.log('Problem saving contact, error: ' +
JSON.stringify(saveResult.error));
var resultsToast = $A.get("e.force:showToast");
resultsToast.setParams({
"title": "Error While Placing Your Order.",
"message": JSON.stringify(saveResult.error),
"type" : "success"
});
resultsToast.fire();
} else {
console.log('Unknown problem, state: ' + saveResult.state +
', error: ' + JSON.stringify(saveResult.error));
}
});
},
})