7

If we have a lightning component, which is a part of managed package, is possible somehow purely from js code to figure out current namespace, i.e. without sending additional request to the server? I know how to do this in apex, but now I'm interested in js solution.

Thanks in advance

3 Answers 3

5

I thought this would not work but it seems to in one of my development org with the component bundle version set to 40.0 (so locker should be enabled)

console.log(component.getConcreteComponent().getDef().getDescriptor().getNamespace());

Which outputs the namespace for the component. No idea if it will continue to work or is scheduled to be removed so use at your own risk

This does throw an error

console.log(component.getDef().getDescriptor().getNamespace());
1
  • for me this works perfectly!
    – Uwe Heim
    Apr 26, 2019 at 17:14
5

How about this

component.getType().split(':')[0];

If no namespace it will return "c".

1
  • This is working fine with Spring 20! Mar 25, 2020 at 16:31
2

I am afraid that this is not possible since it has been possible to query the namespace of the organisation only after the Spring'16 release. There are no global value providers for this in lightning.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .