Is there a way to get request.parameters from a Cl...
# suitescript
a
Is there a way to get request.parameters from a Client Script attached to a Suitelet?
a
request.parameters ? clients scripts don't have request.parameters... or do you mean the other way? from a suitelet to a client script?
k
Like browser url query params?
a
I testing something, request parameters should be in the url if the method is GET, and I should be able to get those with regular javascript, which enough for what I need them… I need to be able to navigate to that very same suitelet if I found an error keeping the same parameters…
a
ok... so the url with the params is a suitlet? and the client script is on that same page with the suitelet response?
and you want to effectively retrigger the same suitelet from your client script?
so you want to parse the url, get the params and then call the suitelet with those params?
...if so then yes you can do that. you'd just use url.resolveScript and add the params to that, and then https.get the result
as for the clientside JS piece you'd want something like this i guess?
Copy code
let paramArr = window.location.href.split("?").pop().split("&"); 
let params = {}; 
for (param in paramArr){
  let keyVal = paramArr[param].split("=");
  params[keyVal[0]] = keyVal[1];
}
e
Here's a function to get any url parameter by name
Copy code
function getUrlParameter(name, url) {
        name = name.replace(/[\[]/, '\\[').replace(/[\]]/, '\\]');
        var regex = new RegExp('[\\?&]' + name + '=([^&#]*)');
        var results = regex.exec(url);
        return results === null ? '' : decodeURIComponent(results[1].replace(/\+/g, ' '));
    }
e
Piling on (and assuming SS2.1):
Copy code
const urlParams = new URL(document.location).searchParams;
console.log(`Script ID = ${urlParams.get("script")}`);
👍 1
a
LOL yeah i figured there'd be newer better web apis these days, there usually are whenever I look 🙂