How to use Javascript SDK with Salesforce lightning component?

I'm currently working on a project where I need to access the Genesys Cloud API from Salesforce. The company is using Service Cloud Voice rather than the embedded Genesys client, so I was planning to use the Javascript SDK from a lightning component.

I've downloaded the current SDK js and put it into Salesforce as a static resource (which is how SF requires you to use external libraries), however it doesn't seem to be available to the component even though I can see that the resource is loaded in the network trace.

Here's how I include it in my component:
<ltng:require scripts="{!$Resource.GenesysPureCloudJavascriptSDK}" afterScriptsLoaded="{!c.afterScriptsLoaded}" />

The "afterScriptsLoaded" function does not get called.

Has anyone done this successfully? My other approach is to just use the basic API, which I would expect to work, but would be nice to use the SDK for authorization and standards.

Any clues appreciated!

I think I've figured it out -- adding notes here for anyone else who stumbles across this.

I had to change require=function().... to **window.**require=function() and now I can access the "require" function from my controller.

The documentation I found to support this was here:
https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/security_share_code.htm

The most important line of the code to note is:

window._counter = (function() {

You must attach _counter to the window object as a requirement of JavaScript strict mode, which is implicitly enabled in Lightning Locker.

Hope that helps!

He Eric,

Thanks for the followup. I am sure someone else will run into the same problem at some point or another.

Thanks,
John Carnell
Manager, Developer Engagement

This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.