get_current or undefined error (JSOM)

Recently, I created a custom survey form with JSOM (JavaScript Object Model) as my choice for inserting data into a SharePoint list form.  It worked perfectly on my test site but when I moved it to our live SharePoint site, I received the following error.
**Uncaught TypeError: Cannot read property ‘get_current’ of undefined**

  var ctx = new SP.ClientContext.get_current(); //**<--ERROR HERE**
        var cList = ctx.get_web().get_lists().getByTitle('2018Survey');

        var itemCreateInfo = new SP.ListItemCreationInformation();
        var listItem = cList.addItem(itemCreateInfo);
        listItem.set_item('CurrentSharePointRole', this._qs("#CurrentSharePointRole").value);
        listItem.set_item('SharePointYammerUseful', this._qs("#SharePointYammerUseful").value);
        listItem.set_item('SharePointYammerUsefulWHY', (this._qs("#SharePointYammerUsefulWHY").value) ? this._qs("#SharePointYammerUsefulWHY").value : "N/A");
        listItem.set_item('AttendedBrownBag', this._qs("#AttendedBrownBag").value);

The site that I moved my code to was heavily customized and it was a publishing site.  I’m not sure if it was the customization or the publishing feature that made my JSOM code to break but after much digging and debugging, I added the following libraries to my html and it worked perfectly.


I hope this helps someone.  Thanks and please leave a comment if you find this helpful or insightful. Also, you are welcome to provide any feedback.  I can take it.  🙂


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: