Brekken Bozzi
Brekken Bozzi

Reputation: 1

NetSuite Phone Number Formatting

I am trying to implement automatic phone number formatting into NetSuite I am having some issues getting my script to work. Basically if someone enters a phone number into a customer record, "1234567890" for example, it will automatically format to "(123) 456-7890". You can see my script below along with the error message I receive when creating a new script record.

enter image description here

Fail to evaluate script:

{"type":"error.SuiteScriptModuleLoaderError","name":"UNEXPECTED_ERROR","message":"missing ; before statement (SS_SCRIPT_FOR_METADATA#21)","stack":[]}

Upvotes: 0

Views: 1121

Answers (1)

Krypton
Krypton

Reputation: 5276

Why do you need a script for this? NetSuite already does this, based on the Phone Number Format setting at Setup > Company General Preferences. Check you have this field set correctly according to your preference.

If for whatever reason it turns out you do need a script for this, there are several issues with the script you posted:

  1. There is a syntax error - mismatched parentheses/braces. Your code editor is trying to show you that with the red brace on line 8 and the red squiggly underline on the last parenthesis (line 23).
  2. NetSuite record level client scripts must implement an entry point function. For formatting phone numbers this would be a fieldChanged() entry point. You would need to wrap the logic contained in lines 10 to 20 inside a function, and then reference that in the return statement at the bottom. EG: If you called the function phone() your return statement would be return {fieldChanged: phone}.
  3. You are using SuiteScript 1.0 API functions (nlapiGetRecordId() and nlapiLoadRecord()) in a SuiteScript 2.0 script. Under some circumstances these functions may be available so it might work, but even if it does, it certainly isn't best practice.
  4. Loading the record isn't necessary. When you implement an entry point function, the function is passed a context parameter. IE: function fieldChanged(context). That context parameter contains a reference to the current record (context.currentRecord). Work with that instead of attempting to load the record separately.

Upvotes: 0

Related Questions