Is there a way to get a suitelet to POST without u...
# suitescript
r
Is there a way to get a suitelet to POST without using the submit button? It's already in use by an existing process. I created a custom button, but the parameter string is going to be too long to pass to GET.
c
You need the behavior to function exactly as a submit button, where it sends a POST request and loads the Suitelet form in the same page?
r
Yep
can you
https.post()
to a suitelet, from the same suitelet?
c
I'm not sure about authentication for that
What's the existing process that's claiming your submit button?
r
Custom "order items" page that generates POs. They want to add a request for quote process which reuses most of the logic.
I've already mostly built that, just trying to handle their submission
e
I've built Suitelets with multiple buttons that all submitted the form. Your button click handler can select the form and call its submit() method.
πŸ™Œ 1
🌟 1
I usually assigned an "action" or similar value to each button so that the POST handler could distinguish which button was clicked
You can do other clever things like add hidden fields that the buttons manipulate before submitting
r
Do you have an example? I'm not the strongest with client scripting. Looking at the dom elements and not sure where to begin. I think I've seen something like this in @mattdahse’s code before. Something like
NS.UI
to refer to the form?
e
There's probably only one
<form>
, so
document.forms[0]
would probably get it
πŸ’― 1
n
(similar) For re-submitting the form after setting values I want to pick up on reload, I've done this before, not sure if it helps:
Copy code
function refreshDetails(context){
        let cRec = currentRecord.get();
        cRec.setValue({fieldId:'records_selected',value:0,ignoreFieldChange:true});
        cRec.setValue({fieldId:'field_changed',value:"anything",ignoreFieldChange:true});
        //
        NS.form.setChanged(false);
        document.getElementsByName('main_form')[0].submit();
        return true;
    }
Note the NS.form line prevents NS complaining that you are leaving the page.
e
Oh if the
<form>
has a
name
attribute like @NElliott’s code indicates, then
document.forms['main_form']
would be more reliable
r
Thanks, all. I'll see what I can come up with after lunch
πŸ‘πŸ» 1
v
NS.form.setChanged(false);
Actual legend. I've been looking for a way of doing that
πŸ’― 1
s
Thought I'd throw out 'too long for GET' is a bit ambiguous - you might be surprised how long that can be. Does anyone know if NS has a documented limit on querystring length in this case (received by a Suitelet)?
πŸ‘€ 1
r
I couldn't find any official documentation. This random website claims to know. They either did some testing or that's just a guess. https://suiterep.com/2021/09/16/pass-parameters-to-url/#:~:text=A%20safe%20limit%20for%20URLs%20is%20roughly%20about%202%2C000%20characters.
m
I agree it’s longer than you probably think, but it’s measured in bytes, not kilobyes for sure.
r
It's a demand driven list on items, which are actually exploded because of a one to many relationship on "Vendor Lead Time" records. Too many lines to reasonably send in a query string. Pretty sure it's not succeeding rn
(with a select all use case)
NetSuite is replacing the param value with an empty array (encoded)
s
r
submit was actually pretty straightforward. thanks @erictgrubaugh
βœ… 1