function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
simon chaosimon chao 

how to pass record id onto a url redirect within the lightning controller

Hi, 
Within my lightning component I have a button, and when you press on it, it calls a function within the controller called userUpload. Upon clicking this button, the page will redirect you to the picture upload page. 

How do i get the record id to associate itself with the page? 

Currently I have, 
//Component: 

<aura:component access ="global" implements="force:hasRecordId">
<div>
     Click below to go to upload page
</div>
 <lightning:button label="Upload" onclick="{!c.userUpload}" />


//Controller
    userUpload: function(component, event, helper) {
        var urlRedirect= $A.get("e.force:navigateToURL");
        urlRedirect.setParams({
            "url": "/upload&id=" + component.get("v.record").id
        });
        urlRedirect.fire();
    },
when i console.log(component.get("v.record").id I get undefined. Anyways to fix this?
 
Raj VakatiRaj Vakati
Change it like this  ..  You need to use component.get("v.recordId") 
userUpload: function(component, event, helper) {
        var urlRedirect= $A.get("e.force:navigateToURL");
        urlRedirect.setParams({
            "url": "/upload&id=" + component.get("v.recordId")
        });
        urlRedirect.fire();
    },

 
simon chaosimon chao
i console logged component.get("v.recordId")
and i got blank.
Ambika Arora 23Ambika Arora 23
Hi, how to pass record number onto a url redirect within the lightning controller??
Suraj Tripathi 47Suraj Tripathi 47
Hi simon,

Try below code it should work if not then check your recordId data.
 
//Controller userUpload: function(component, event, helper) {
var recordid= component.get("v.recordId");
var urlRedirect= $A.get("e.force:navigateToURL");
urlRedirect.setParams({ "url": "/upload&id=" +recordid });
urlRedirect.fire();
},

If you find your Solution then mark this as the best answer. 

Thank you!
Regards 
Suraj Tripathi