is it possible to call a restlet from a suitelet w...
# suitescript
c
is it possible to call a restlet from a suitelet without using user credentials or oAuth?
p
is it the suitelet it self that calls the restlet or is it a client script attached to that suitelet? because a client script does it very simply:
Copy code
var dataFromRestlet = https.get('/app/site/hosting/restlet.nl?script=200&deploy=1');
c
Currently it is a suitelet. But maybe i should change it to a client script: Currently my suitelet iterates through a lot of searches to find workorder regarding a specific item(that the user selects), and then afterwards another search will look for similiar items and then at their workorders. The searches are used to get the actual runrates of a lot of different workorders, that share the same traits. But i ran into a script execution usage limit, that prevents me from doing more. Therefore i would like to do the searches and some of the calculations in the restlet, and then return the results to the suitelet, that then will show the user the results. But maybe i should change the suitelet to a client script then?
p
are you refreshing the suitelet with each selection? otherwise it's a client script that triggers on field change.
c
Yes, i currently refresh the suitelet with onRequest, when a button is pressed on the page
Dont know if this is the best solution though
to clarify currently the the suitelet does not call the restlet yet, i have not figured out on how i want to do it. Most of the documentation that i found, uses user credentials to call the restlet, but that is not viable
The reason that i think that it is not viable, is because a lot of users are going to use the page, not just me.. So if i fill in my own credentials, the script would not work for the concerned users.
p
you can get it dynamicly with the runtime module
c
Ahh get the users credentials dynamicly?
I need the signature(password) aswell, for the current user, but i cant seem to find a function within the runtime module that can return that value
p
if you use client script you are already authendicated and dont need thoose informations
i think there is a similar way in a suitelet, but cant remember it of the top of my head
c
Alright, so your recommendation is to convert my suitelet to a client script.
So that the
client script takes the user input, which is then sent to a restlet, that gets the data and handles it, and then returns it to the client script again?
So this:
Copy code
var dataFromRestlet = https.get('/app/site/hosting/restlet.nl?script=200&deploy=1');
Would just work with the post from the clientscript, and then from the restlet i post it back to the clientscript?
A client script would not be able to create a netsuite page though, which is what i need right now. So i dont know if thats a viable option aswell
p
it would be the suitelet that creates the page, then attach a client script to trigger on field change for somthing similar
c
Alright, so the suitelet creates the page... then the user enters the page, and enters an item into the field and presses submit. Then the client scripts send the request to the restlet, that then creates the searches, handles the data, and then returns it to what? The client-script or the suitelet?
p
if you want it to be on submit, it would be the suitlet that sends the request. or you can make a dynamic sublist that the clientscript manipulates. either by pressing a button or simply changing the item field (see client script trigger "fieldChange")
c
"if you want it to be on submit, it would be the suitlet that sends the request." I would like it to be on submit, but yes, then again its the suitelet, but then we are back to the first problem again. How do i call the restlet from the suitelet 😅 Without using my own user credentials.
p
you can set up an "integration x" user that it always uses, so it not any individual. this is how many 3. party integrations are made
c
Yes, but thats for 3. party external integrations, but would that really make sense?? since this is all internal netsuite stuff
p
It's also used frequently for internal scripts
c
Alright i see, but thats oAuth i need to use right then?
any tutorials on how to do this?
Not really sure on what i would have to fill, and what i should leave blank. I would guess that token-basen-auth should be ticked and the outher should be unticked: But would about oAuth2? and the redirect URI field?
p
c
Thanks already looked at all the NS documentation tho, they all use user credentials 😅
t
@c c Perhaps another approach would be to use Suitelets instead of the RESTlets. That would help you avoid the overhead and complexity of calling the RESTlets. If you look at the most recent beta of the SuiteQL Query Tool ( https://timdietrich.me/netsuite-suitescripts/suiteql-query-tool/downloads/ ) you'll see how I'm doing that (sort of). In the case of the tool, it renders the UI via the Suitelet, the UI then sends XMLHttpRequest requests back to the same Suitelet, and the Suitelet essentially acts as an API and processes the requests. (In the case of the tool, I'm handling all of that in a single Suitelet to make the tool easier to distribute, becauseI don't have the ability to distribute it via a bundle.) If you have any questions about this approach, let me know.
r
I've also used the request/response loop to make data intensive processes hover under governance limits in a suitelet. I created a full crud suitelet that updated custom records and just recommended in the help to only update 20 records at a time. Not sure if your process would be compatible.
As I mentioned earlier, you can do lookups or searches with complex criteria to avoid iteratively searching.
c
Yes, but its not because im looking up to many records, im having script usage limitations
Not search limitations
r
Record loads are just one reason you could have script usage limitations. I'm saying to figure out what API's are causing you to go over on governance and come up with a strategy for bringing it down.
c
This is the part where i run into issues,
yes i know i loop the search multiple times, but i have multiple workorders that i need to search for
that i find with another search
an example would be that i have an array, which contains around 300-400 different workorders. Which have been found via another search. Now i need to find the actual runrates for these workorders, and to do that i need to look up every single one. I tried splitting the search into blocks, which WORKED, that made me able to do more lookups. But after i divided the searches into blocks, i went on for a little while and added some more logic, which then caused the script usage limit to trigger. And thats why the searches are not really the cause of the problem, even tho they of course are contributing to it.
@reptar
r
runPaged is five units, so excluding anything else going on in your suitelet, you have a maximum of 200 iterations in that for loop. (1k/suitelet) therein lies the problem
c
Actually its under 200 iterations when i tested it
but yes if it exceeds 200 it would be a problem
but when its under 200 iterations, i still get the error
r
No, *exluding anything else going on in your suitelet
There are plenty of other api calls using governance
b
your problem is that you are doing one work order search per search result
change your work order search to get data for more than 1 work order at a time
ideally using internalid instead of transactionnumber so you can use the anyof operator
as written, you need to combine a bunch of filters using
OR
✔️ 1