3

In our managed package, we have a particular page where we have some default javascript that runs some calculations on some fields as you type and I am in the process of converting this page to LWCs.

The particular issue I have is that some of our clients require slightly different calculations to be run. I would like to upload these as functions in a javascript file inside a static resource in their org, but I need to be able to reference this from inside out managed package. Is this even possible? I'm struggling to find a way.

It doesn't have to be a static resource - it could be a LWC with no UI (just a javascript file).

Either way, the problem seems to be adding javascript from outside of the managed package into a component that is inside of the package.

Any thoughts would be hugely appreciated!

Thanks

Andy

1
  • 1
    I'm about 90% sure that the answer to this is "not in LWC." You may have an easier time of it in Aura, though. – sfdcfox Aug 26 '20 at 14:01
2

Ok - I came up with a solution. It's not the best because it uses eval but since all we will be doing are some simple calculations on object fields and then returning the object, I think it's fine.

In my apex controller, I simply query for the static resource (Id and Body) with a specific name - this will return a static resource, regardless of whether it originated outside of our managed package or not, and the javascript content as a string in from the Body field. If something is returned, I simply eval it which gives me a function to call on my object.

I've tested it and it works perfectly.

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.