Hey all, odd one again here: When calling a restle...
# suitescript
c
Hey all, odd one again here: When calling a restlet from an address form script as post it seems the form doesn't then save. It's hitting "return true" fine on the address script in the debugger but just the form is just sitting there. If I click save again it gives the normal warning of "you have already submitted this form". I've confirmed that when I don't call to the restlet it saves fine. I've put a return at the start of my restlet code to rule out it's contents and it still stops the record saving. It seems to be just the act of calling nlapiRequestURL from the address form script that stops it saving. Any ideas?
s
You mean to say you are trying to save the form ?. But it doesnt save when you are calling the restlet?
c
Yep.
Restlet returns data fine and then the original address script hits it's return true and then the form does nothing.
The backend Netsuite scripts showing in the Chrome debugger seem to also flag the form as valid for saving too.
s
Where is the restlet called?
c
From within the client side address script.
s
Can you try return true after you call the restlet?
c
Yup I've tried that and it hits that line and the form just sits there not saving.
Tried it before the restlet call and it saves fine.
l
Are you using 1.0 or 2.0? In both calling external API in client script may be tricky. In 1.0 you have callback function and this callback parameter is not there in server side script(also in debugger), so that's why it can behave in a diffrent way in debugger. In 2.0 you need to use promises. Without code it is hard to guess though...
c
Main address form script
Restlet script being called by address form script.
Hopefully this helps?
l
@CraigyD - to be honest I m not sure that you can call restlet in debugger withour providing authorization parameters, so in debugger I would gess your response body will be something saying that you are not authorized, so that's why in debugger it may be different. I would start from login what do you have in validAddressResult. the other thing is that for restlet request you are using "Content-Type": "application/json" but you are returning a string 'false' which may cause error. add some nlapiLogExecution to restelt and maybe some alerts to client script to check what is going on and what values are returned. the other thing is that you are messing == and === not sure fi this is intended
c
The debugger is just tracking the in place script on the form. It's sending and receiving from the restlet fine. The content type is for the data being sent which is JSON. The string false is because it won't accept returning a non-string value from the restlet. I've added in the checks and it does go all of the way through the script no problems which is why it's so weird. It gets through it all then returns true and sits there not saving. The only place I can see I used == instead of === is for the user ID and that's admittedly just being lazy for coercion and runs fine!
l
I am always starting from checking all the code paths and variable values. Have you logged all the important values in client script (or just alert them if you preffer). Also have you checed browser console for errors?
BTW I am succsefully returning non string value in RTestlet for contet type "application/json", but it has to be a JSON like { isValid: true}
c
I've both logged and alerted and all shows as fine. I've stepped through with the debugger and it actually completes and exits the script then moves onto the standard form scripts which show the record as validated to be saved == true so it's looking like a bug.
Sure, you're right I should really return it as a JSON object but I don't think it will affect anything as it's a string value either way. I shall try it to explore everything!
l
and did you open console and checked that there are no errors?
c
Yup, no errors! This is the really weird thing. I'm thinking it's something to do with the form being confused loading a back end script from within the client.
I've amended to use a stringified JSON object return and works exactly the same. Still freezes. Weirdly it ONLY seems to hang on save when using the Custom address option on transactions. Works on editing existing addresses fine. It's the same form etc.
l
ok so some bug - call support and good luck...
c
Thank you for your help!
s
Can you try saving the restlet value in variable and do something like if(restletValue){return true:}