Unexpected Error with Arrow Functions in Service File

in , November 7th, 2024

Common Cause of Extension Errors

If you are pulling code off of the internet to put into your extension’s service file, make sure to reformat any shorthand arrow function expressions. If arrow functions stay in the code as is, you may get an “unexpected error” on deployment or a syntax error on activation.

Resolving the Arrow Function Error

Just a handful of characters would have to be added or converted to make the arrow function code workable in SuiteScript 2.x. For example, this line of code to find if an array of objects has some value in the object parameter “name”:

if (arrayOfObjects.filter(e => e.name == "Select This").length > 0)

would be converted into this:

if (arrayOfObjects.filter(function(e) {return e.name == "Select This"}).length > 0)

Author: John Baylon


Got stuck on a step in this article?

We like to update our blogs and articles to make sure they help resolve any troubleshooting difficulties you are having. Sometimes, there is a related feature to enable or a field to fill out that we miss during the instructions. If this article didn't resolve the issue, please use the chat and let us know so that we can update this article!

 
 

Want to keep learning?

Our team of NetSuite professionals has written articles on a wide variety of NetSuite topics, from SuiteCommerce tips, to recommended NetSuite solutions, to available support services, and more! 

Your cart