Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Autocomplete on String Literals #45

Closed
JonnyBoy333 opened this issue May 22, 2017 · 7 comments
Closed

Autocomplete on String Literals #45

JonnyBoy333 opened this issue May 22, 2017 · 7 comments

Comments

@JonnyBoy333
Copy link
Contributor

JonnyBoy333 commented May 22, 2017

I realize this may be a lofty goal but it would be truly amazing if we could get intellisense on what strings needed to be in specific contexts, like we had in suitescript 1.0 in eclipse. Enums may also be a solution for this, however, there would be a very large number to setup and it would require the user to remember how to invoke all of the different enum declarations. Example:

Typescript Definition:

interface GetSublistValueOptions {
    /** The internal ID of the sublist. */
    sublistId: string | 'items'  | 'expenses' | 'addressbook'; //<--- string literals defined here
    /** The internal ID of a standard or custom sublist field. */
    fieldId: string;
    /** The line number for the field. */
    line: number;
}

Would give you completion like this:
autocomplete

Ideally the string options would be limited to that specific record type so you wouldn't get a sublist like 'expenses' available on a sales order record, for example.

I should also add, if a structure is agreed upon I would be happy to help in filling in the definitions.

@ShawnTalbert
Copy link
Contributor

ShawnTalbert commented May 22, 2017 via email

@johnogle222
Copy link
Contributor

I've been thinking through ways to make this happen - which may be a bit easier now that the SDF CLI tools are out. We would run a script to download all of the customization objects in the system and generate some local type aliases that are utilized through the library.

I haven't really broken much (or really any) ground other than brainstorming some potential paths to proceed down. No proof of concept or anything like that.

If you would like to get started on something I'd be happy to help out wherever I can. Otherwise, as you put it, this is a bit too lofty for what my short term time availability will allow for now. I will get around to it eventually but have some other priorities at the moment.

@JonnyBoy333
Copy link
Contributor Author

Downloading all customization certainly would be an ideal goal. It might be worth starting with just the default fields before trying to tackle custom fields. Not being an expert at TypeScript I was thinking that the record type could be specified in the context definition

function beforeLoad(ctx: EntryPoints.UserEvent.beforeLoadContext.SalesOrder) {})

Or else it would be cool if you could further define a type when you assign a variable

let rec = <SalesOrder> ctx.newRecord;

@ShawnTalbert
Copy link
Contributor

I actually have plans to create a tool to pull down ALL the customizations in a NS account, generating corresponding NFT-SS2 (TypeScript) classes/enums for them. Default fields are already being defined directly in NFT.

With this, we'll finally have a programming environment in NS near what we had 15 years ago in other programming environments. :\

@JonnyBoy333
Copy link
Contributor Author

I have been working on trying to accomplish this and have made decent enough progress that it is now worth showing. If you are interested in testing please download my fork here: https://github.com/JonnyBoy333/typings-suitescript-2.0/tree/record-field-definitions

I had three goals when looking at this feature:

  1. Autocomplete for every standard NetSuite field you can find in the record browser.
  2. Type safety for all standard fields (i.e. if the field is a checkbox it should be recognized as a boolean by typescript).
  3. Ability to add custom fields.

What is accomplished so far:

  1. Autocomplete on all standard NetSuite fields.

In order to make this work, I have created individual files for each record in NetSuite to capture all the fields and put them in function options that are then imported into the main record file. There is a generator file in the 'helpers' folder that scrapes all the pages of the record browser to create these files which can be run when new versions of the record browser are released to update fields.
Autocomplete on main field strings from the context type:
current_rec_main_field

Autocomplete on sublist strings:
current_rec_sublist

Autocomplete on sublist field strings:
current_rec_sublist_field

Autocomplete on main fields from a loaded record:
loaded_rec_main_fields

  1. Type safety. There is a bug in typescript that prevented me from accomplishing this. The files are all setup to support it from the categorization of the field ID's by field type when the issue is fixed.

field_types

The issue is that when you create function options with different resulting types (i.e. boolean, string, etc.) you lose auto-complete on all of the strings, which is a major drawback. The issue has been logged here so please thumbs up: microsoft/TypeScript#17127.

  1. Custom fields. It would be fairly simple to add a file to add custom fields and import those into records.. but that doesn't accommodate people like me. That is, people who have this package installed globally and work in multiple NetSuite accounts. I need to come up with a way to include custom fields on a per project basis and import them into this module. If you have any bright ideas let me know.

Note: I did all my working using VSCode as my editor. I did try this in both Atom and Webstorm. Atom handled it ok but the auto complete is not as good as VSCode IMO but Webstorm did not always pick the right auto correct options. So I would really only recommend using this in VSCode.

@ShawnTalbert
Copy link
Contributor

ShawnTalbert commented Aug 6, 2017 via email

@JonnyBoy333
Copy link
Contributor Author

@ShawnTalbert I have looked into NFT, it is quite impressive, adds a lot of useful capabilities. It's a little tricky for me to implement, however, since I'd have to convince the rest of my developer team to start using it and installing it into each of our new accounts, which is a tough sell. It's easier, for now, to just use the typescript library.

Also worth considering, I have support for the field IDs or all 182 records in NetSuite. So whatever record you load, you'll be covered.

@MrRob MrRob closed this as completed Sep 18, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants