10

I'm trying to access current record id in a Lightning Component when put into Utility Bar. But it comes out to be empty all the time. I've implemented force:hasRecordId interface in my component but recordId attribute remain empty when I launch the component in Utility Bar.

Is there a way we can achieve this function of reading current record id in utility bar?

2
  • Did you make any progress with this? I'd love to be able to get some context in my component!
    – Matt Lacey
    Mar 7, 2017 at 12:21
  • Nopes, nothing yet.
    – VarunC
    Mar 7, 2017 at 13:42

2 Answers 2

3

I believe this may have been resolved in the Winter '18 release. I just added a component to the utility bar that implements force:hasRecordId and it does pull it in.

For reference, here is the relevant component attributes:

<aura:component implements="force:hasRecordId,force:lightningQuickAction,flexipage:availableForAllPageTypes">

And here is the JS controller that fires on init:

handleRecordChange: function(cmp, evt, hlp) {
    // only call server if user is on step 1
    var step = cmp.get("v.step");
    if (step == 1) {
        var recId = cmp.get("v.recordId"); 
        if (recId != null) {
            // delegate to helper
            hlp.getRecordInfo(cmp, cmp.get("v.recordId")); 
        } else {
            cmp.set("v.recordContext", false); 
            cmp.set("v.step",0); 
        }
    }
}

I think for this to work your Lightning Component needs to be on API version 41.0. You can adjust this by clicking the "Bundle Version Settings" button in the cloud dev console.

Hope this helps!

2
  • 1
    Hey @kev4ev, do you have an example you can share? Just tried in a Winter '18 org and it appears it's still not working. Oct 20, 2017 at 20:57
  • @GusMelendez Just updated my answer with some sample code. Note the last part regarding setting your component API version to 41.0
    – alphaBytes
    Oct 23, 2017 at 14:46
0

this works for me to get recordId for a component in the Utility Bar:

<aura:component description="Aura Container in Utility Bar for LWC cmp" implements="force:hasRecordId, force:lightningQuickAction, lightning:utilityItem" access="global">

<c:childLwcCmp recordId="{!v.recordId}"  />  

</aura:component>

export default class childLwcCmp extends LightningElement {

_recordId;

@api
get recordId() {
    return this._recordId;
}
set recordId(value) {
    this.setAttribute('recordId', value);
    this._recordId = value;

//for the first time NULL comes, but then immediately the current recordID comes from the aura

    if (this.recordId == null) {   
        console.log('-/-NULL-/-', this.recordId);
    } else {
        this.doInit();
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.