This article is relevant if you are interested in the advances of Artificial Intelligence and NetSuite programming.
Background
Many articles have been published on Open AI’s ChatGPT artificial intelligence capacities in the last few weeks. I started to play with it — indeed, I was delighted with how well it understood my requests. In a conversation with my technical team, some are just getting familiar with ChatGPT. So, I asked a basic SuiteScript question to show how it works.
Please Write Me Some SuiteScript
Here is what I asked ChatGPT:
“Please write NetSuite SuiteScript to upload a file to the file cabinet”.
ChatGPT Response to My Request to Write SuiteScript
In less than 15 seconds, here is what it responded with (click on the image to see how it looks to get a response). The SuiteScript is version 1.0, which is still supported but no longer being developed.
To upload a file to the file cabinet in NetSuite using SuiteScript, you can use the nlapiCreateFile
function. This function allows you to create a new file record in the file cabinet and upload the file data from a local file or from a remote URL.
Here is an example of how you can use this function to upload a file to the file cabinet:
function uploadFile(fileName, fileType, fileData) { // Create a new file in the file cabinet var file = nlapiCreateFile(fileName, fileType, fileData); // Set the folder for the file file.setFolder("1234"); // Replace "1234" with the internal ID of the folder // Save the file to the file cabinet var fileId = nlapiSubmitFile(file); return fileId; }
To use this function, you will need to provide the following arguments:
fileName
: The name of the file that you want to uploadfileType
: The file type, such as “PDF” or “JPG”fileData
: The file data, which can be either a string containing the file data or a JavaScript object with the following properties:path
: The path to the local file that you want to uploadurl
: The URL of a remote file that you want to upload
Note that the nlapiCreateFile
function has a number of other optional arguments that you can use to set additional properties for the file, such as the file description or the file encoding. You can find more information about these optional arguments in the NetSuite Help Center.
I hope this helps! Let me know if you have any questions or need further assistance.
I refined my question to ask for SuiteScript 2.x, and it appropriately refined the answer. Click the image to see the response.
Keeping Up with NetSuite Skills and Capacities
I speculate we are really going places with artificial intelligence. It’s important to watch this new capacity and learn how it opens up our future. My instinct is that we must keep working on “upping our game” to be valuable to others.
If you found this article relevant, feel free to sign up for notifications to new articles as I post them. If you want that old fashion and reliable NetSuite technical leadership that is becoming old-world, let’s have a conversation.
I don’t know if you have experimented more with this, but if you ask, chatGPT will write a script in SuiteScript 2.0 as well. It has written some stuff that doesn’t make sense though, using fields that don’t seem to be available. It also seemed to mix Javascript and XML in one of the scripts that we had it write.
Thanks John. Yes, it does seem to try to distinguish 1.0 vs. 2.0, but it is not fully reliable. I appreciate that it shows promise.
Marty