Join 50,000+ readers learning how to use AI in just 5 minutes daily.
Completely free, unsubscribe at any time.
Summary
Learn how to execute SuiteScript 2.x directly in the browser console to interact with NetSuite records more efficiently. This allows developers to access hidden fields, manipulate data, and run unit tests without deploying scripts. The video demonstrates using the Require.js framework, snippets in Chrome, and exploring APIs for streamlined SuiteScript development.
Highlights
Control and interact with NetSuite records through SuiteScript in the console for greater efficiency. โจ๏ธ
Discover hidden fields and buttons using SuiteScript APIs directly in the browser. ๐
Run unit tests directly in the browser to prevent deployment hassles. ๐งช
Explore and test NetSuite APIs faster by typing functions directly into the console. ๐
Utilize the Require.js framework to load only necessary JavaScript modules. ๐
Create and save Chrome snippets to streamline script usage and module loading. ๐พ
Learn to load various modules using the Require statement and access their functionalities. ๐
Manipulate search results and examine record types and fields through loaded modules. ๐
Ensure thoughtful usage of SuiteScript to prevent unintended data changes in production. ๐
Key Takeaways
Execute SuiteScript directly in the browser console to access and manipulate NetSuite records easily. ๐ฏ
Use SuiteScript 2.x for unit testing, API exploration, and field manipulation without deploying scripts. ๐
The Require.js framework helps load necessary modules for efficient script execution. ๐ฆ
Chrome snippets can store reusable scripts for quick access to frequently used modules. ๐
Be cautious running scripts in production environments to avoid affecting live data. โ ๏ธ
Overview
Step into a world where interacting with NetSuite is far more hands-on with SuiteScript executed right from your browser. Yes, SuiteScript 2.x lets you do just that, giving developers a powerful tool to access the NetSuite records without the hassle of additional deployments. Whether it's finding hidden fields, running tests, or pulling API information, executing scripts directly in the console has never been easier.
During the video, viewers are taken through a detailed walkthrough of using the Require.js framework to dynamically load JavaScript modules relevant to their scripts. This method ensures that only the necessary bits are brought into play, making execution as smooth and quick as possible. Developers are also introduced to the world of Chrome snippets, showing how script snippets can be saved and reused efficiently.
The video also comes with necessary precautionary advice about running console scripts in production environments and ends with a call for further inquiry if needed, stressing that while powerful, these tools need to be wielded carefully in live systems. The session packs in excellent insights for any SuiteScript enthusiast keen on optimizing their scripting process.
SuiteScript in the Console Transcription
00:00 - 00:30 welcome to this presentation which will cover executing suite script 2.x in the browser console this video and its contents apply equally to sweet script version 2.0 and version 2.1 and likely any future versions they're based on the same framework during the course of this you will
00:30 - 01:00 hopefully learn how to use the browser console to execute suitescript um the intent is that on a net page you'll be able to open the browser console and quickly access the data on that netsuite record or any other record within the system to which you have permissions via sweet script what can you do with this well the first thing you can do is find hidden field buttons
01:00 - 01:30 there are a lot of fields that are on almost any record in netsuite that aren't exposed in the form or that may be hidden behind a tab or under some internal navigation on that page that you can't get your hands on right away using the sweet script apis in the console you'll be able to find all the body level fields all the line level fields regardless of whether or not they currently have content or they've been hidden or disabled on the forum
01:30 - 02:00 and speaking of hidden and disabled fields wouldn't you like to be able to set or clear the values in those fields without having to resort to a csv import or some other method that gets around the limitations of the ui well the sweet script api can do that you can set fields that are normally disabled you can set fields that are hidden or
02:00 - 02:30 inline you can clear those fields you can query what they have and figure out what's actually on that form in addition to that near godlike power uh sweet script 2.x in the console will allow you to unit test your sweet script functions if you are a developer and you're trying to figure out maybe what some piece of code does or how it works or you want to test it make sure that it's going to function in the context of your
02:30 - 03:00 larger script you don't have to deploy it run it add some logging check the logs all that nonsense you can often just paste the function into the console and run it right there on the page now that comes with a warning anything you run in that console is actually running against that current environment so if you're in production and you're running sweet script in the console you're affecting records in your production be very careful about that
03:00 - 03:30 and lastly the ability to run sweet sweep in the console will let you explore the api uh how many times have you tried that you you're rolling running along writing something and then you need to find the enumeration for this record type or whatever it happens to be you can just type it up in the console and and the
03:30 - 04:00 library is loaded and it spits out the the entire email for you we'll demonstrate that later um you'll be able to test out a function that you're just learning but if you've never tried you know a giving function typing it in the console and seeing what it does is much much faster than creating a script around it to log out the results suite script
04:00 - 04:30 2.x uses the require.js framework and this is a module loader that optimizes javascript execution by only loading the modules that need to be loaded for a given execution you can learn more about this at require.js
04:30 - 05:00 you can learn more about the choir.js at requirejs.org but for the purposes of this demonstration you don't need to know much more than what the natural structure is for the require.js pattern
05:00 - 05:30 in this pattern we're going to use the require statement which has two pieces the first is an array i have it listed here as path to module path to module you can have one or more modules there and we're looking at how does the execution reach the module that we want to load and the second piece is a function that function uses the actual modules in the order they're presented in that array
05:30 - 06:00 and within that function we're going to actually call all the code that uses those modules the upside to this is that the modules are guaranteed to be available by the time our code is run the downside is that after this function is done and reaches the end of the cut the execution we no longer have access to those modules
06:00 - 06:30 so that's enough with the theory let's let's take this to the actual netsuite environment and look at some of the practice here is a sales order that's open in edit view although i could just as easily be in view mode to access this you'll need to first find the console if you're not familiar with how to get to
06:30 - 07:00 the browser console i am in chrome right now you there are a couple of ways to get to here if you are on a mac as i am it is option command i that will open the browser console alternately if you right click on any page and go to inspect it will also open chrome dev tools and it will look something like this
07:00 - 07:30 the console is this lower part you don't see it immediately you can use this navigator up here to find it this will bring you to the same place this makes the entire console available i'm going to clear it because there's a lot of noise in that suite and now it's just a blank canvas for me to write my script upon if you're back in this elements view it's just this lower part
07:30 - 08:00 and to demonstrate how this required pattern works i'm just going to type it in the console here i'm going to increase the size to make it easier to see so the first part is the require statement and then i'm going to open square brackets for the array and i'm
08:00 - 08:30 going to load the n current record [Music] module and it's important to note here that you can only load the modules that are available to client scripts so there is a limitation here there are some modules that don't you cannot load from a client script and therefore they're not going to be exposed to your name available among those i think is the file module
08:30 - 09:00 and the next piece of the required statement is the function in this case function we're going to use current record i'm just naming giving this an arbitrary name you can name it anything but current record makes sense and i'm going to say within this function i'm going to assign a variable tool to this called rdc rec and i'm going to assign that the value of currentrecord.get which will get me
09:00 - 09:30 the value of this loaded record in the in the which i'm looking at right here in the pane i'm then going to set the value of this field to field id of memo to my new memo so i'm using the print record module getting the record and that record i'm going to set the value using the dot set value method on the record object the current record object to [Music] my new memo
09:30 - 10:00 and as soon as i do that it spits out some garbage here but you'll notice that my memo now has my new memo in it that's pretty cool so i've cleared out the console and
10:00 - 10:30 you're probably saying to yourself that looks like a lot of garbage to type every time i want to do something and you're not wrong um there is a much easier way to do this other than typing all that out every single time and in fact this opens up the ability to use a lot of modules anytime you want um i've got a whole list of them that i like to just keep at my fingertips all the time so i'll show
10:30 - 11:00 you what that looks like first we're going to find the snippets functionality in chrome going to be up here if i click here i'm going to see a lot of things that aren't visible normally console sources network etc but i really want to sources once i have sources here
11:00 - 11:30 i drag this out so it gives me a better view of what i've got going on here there are a lot of other things other than page and file system here but those are going to show probably first i'm going to go here and just show snippets snippets allow me to have a piece of javascript that i can run again and again it's saved in my my installation of chrome and it's always
11:30 - 12:00 going to be available whenever i open from i'm going to create a new snippet here and i'm going to name it so let's put modules and for every module that i want to expose in the console i'm going to declare a variable the top of the
12:00 - 12:30 snippet generally i like search those are your standbys you absolutely have to have those every single time right current record also handy let's start with those then we're going to type a require statement
12:30 - 13:00 we're going to bring in and search [Music] here and this is what we type our function our function has the parameters that
13:00 - 13:30 map to these this array of modules we're loading so search i'm going to actually call them s r [Music] and correct and the reason for that is because i want the namespace of search record and current record to be global in my console when i'm done so i don't want to reuse them here it just adds confusion and then here
13:30 - 14:00 all i have to do is say that search which i've declared outside of this function is now equal to the module that i've loaded which is s and record equals r which i just brought in and current record equals
14:00 - 14:30 and you can do this with as many modules as you like i've got just a ton of these things that i have to bring in just for fun let's also add the message module i'm going to sort of reformat this in a more scalable way
14:30 - 15:00 so you can see what's going on here so i've added message up here to the global variable i'm loading the message module here i have to pass it of course to my
15:00 - 15:30 function i'm just going to say m perfect and just to let future me know that this worked i'm going to put a console log statement it says modules are loaded
15:30 - 16:00 semicolon at the bottom and i'm going to hit ctrl s or command s on my mac to save this now it's saved all i have to do is find my snippets again anytime i want to i'll be honest i refresh the page here
16:00 - 16:30 i can navigate to any netsuite page almost any netsuite page open the console find my snippet run my snippet and i get this modules loaded message right here beautiful i can then clear my console if i want to and then i can say oh let's let's try and load this record let's go [Music]
16:30 - 17:00 record load and then of course the record dot load api requires a type parameter i can say record type sales order [Music] which i'm going to pull from the url
17:00 - 17:30 right there okay it's done now i can use the record apis and i can say rec get fields look at this i have got a tremendous number of fields 282 fields and on this record
17:30 - 18:00 those are just body level fields and that's basically your sales order if you use this also to save brick [Music] get submiss fields requires submission i want to get the items because really we're in a sales order what else is our c look at this a tremendous number of
18:00 - 18:30 fields on the item sublist most of which you don't you don't get to see in the ui uh but they're there there's all there's all of all the ids including custom fields may or may not be hidden also in here you can do access the record api and list out
18:30 - 19:00 types of records in your account look at this this is the record dot type ena if you need to know what the you know the enum is for customer message there it is customer message um but the if it's you know employee type there it is uh just a tremendous amount of information here just about the record id of the record type
19:00 - 19:30 um you can load a search this is true this is a super helpful since i loaded the search in my search module in my console i can then look at the search apis too with the search types right there there's an amazing amount of those i have a specific
19:30 - 20:00 search i want to load i can do that bastion id the search that i want to examine
20:00 - 20:30 there it is now i can take a look at this search object which i've named s and just look at its columns what columns are on this search look at that 12 columns each one i can drill into oh is there a formula here is there a function is it a join is there a label what's the name of it that's the id i can i can figure out what's going on with the search i can look at its filters
20:30 - 21:00 filter expression isn't that amazing
21:00 - 21:30 but it's even more impressive if i can actually run the search right here in the console which we can do with a little bit of javascript
21:30 - 22:00 a little bit of javascript in the
22:00 - 22:30 console i can now run that search if i wanted to and display its results i'm going to do this by just referring to the search with my variable using the dot run api which gives me an iterator i'm going to use the each function to iterate over the values the result setting and i'm going to declare a values object
22:30 - 23:00 within this loop to hold the values of those columns for each of these columns i'm going to assign the name of that column as a property in the values object and i'm going to assign the result of that property to the value of that column then i'll log out the results and i'm actually going to [Music] run it and because i didn't return true in here it's only doing it once
23:00 - 23:30 that gives me one result and that's the first result of our search pretty amazing i could then manipulate this search i could add more columns remove some columns or get the second result whatever i wanted to do so that's the basics of how you run sweet script 2.0 in the console you can use this snippet functionality to store as many modules as you want those that are supported
23:30 - 24:00 on the client side at least are can be added to this sniff it in the same pattern here my the one i personally use that's about 14 or 15 modules being loaded um and even though i've shown this in in sweet script 2.0 using variables instead of constants using the word function instead of error notation you could easily use the sweet script
24:00 - 24:30 2.1 api which uses es6 to clean this up and make it more modern but in the interest of making this as accessible as possible i chose to use the the older the older format for the code so great if you have any questions i hope you found this useful and if you have any questions please reach out to
24:30 - 25:00 us at 360 cloud solutions to be able to help you to answer whatever questions you have about this thank you