I'd like to ask if anyone can help me figure out w...
# suitescript
u
I'd like to ask if anyone can help me figure out what I'm missing or doing wrong. I'm attempting to send a value from a Suitelet (triggered by a button) to an HTML page hosted on our File Cabinet, process some inputs, and ideally send the inputs back to the Suitelet for post-processing. My goal is to be able to take inputs from the HTML form and send it back to the Suitelet, and process it with Netsuite modules. I've successfully sent data from the Suitelet to the HTML via headers, but I'm having difficulty retrieving data from the HTML back to the Suitelet, getting a "You have attempted an unsupported action." error, without much leads to go by. I attached a reply to this thread with a code sample to avoid clogging the channel feed, and any and all input would be appreciated.
HTML
Copy code
<form method="post" action="<https://SuiteletHostedOnFileCabinet.js>">
    <table>
        <tbody><tr>
            <td id="ttext">Test Text</td>
            <td><input id="input1" placeholder="Anything" name="Input1" required="" type="text"></td>
        </tr>
    </tbody></table>
    <br>
    <button type="submit" class="btn" formmethod="post">Test Form</button>
        <script>
            //testing if the Suitelet value passed through
            let queryString = window.location.search;
            let urlParams = new URLSearchParams(queryString);
            let id = urlParams.get('recid');
            document.getElementById('input1').innerHTML = id;
        </script>
</form>
Suitelet
Copy code
/**
  * @NApiVersion 2.1
  * @NScriptType Suitelet
*/
define(['N/https', 'N/log'], function callbackFunction(https, log) {
  
  function getFunction(context) {

//record ID was passed from a Client Script to the Suitelet
    var id = parseInt(context.request.parameters.custom_id,10);
    let headerObj = { name: 'recid', value: id };
    var contentRequest = https.get({ url: "<https://HTML_hosted_on_File_Cabinet.html>", headers: headerObj });
    var contentDocument = contentRequest.body;
    context.response.write(contentDocument);
  }

  function postFunction(context) {

    let test = Object.keys(context);
    log.debug({ title:"Testing variable passthrough", details: test })
    context.response.write(test);
  }

  function onRequestFxn(context) {

    if (context.request.method === "GET") { getFunction(context) }
    else { postFunction(context) }
  }
  return { onRequest: onRequestFxn };
});
b
you action looks like its posting to the suitelet's file
instead of the actual suitelet
post to the actual deployment of the suitelet
1
plusone 1
w
the form action value should be the external URL of your Suitelet, this can be found on the Script Deployment of the Suitelet, and make it available externally and get the external URL
🙌 1
b
its also more normal to have the suitelet write the html instead of opening an actual file in the file cabinet
you get the bonus of the action automatically pointing to the correct url
u
While I've yet to finish the project, I've successfully passed through the input of the field through context.request. Many thanks to you two! Just an afterthought question for @battk though: what did you mean by having the suitelet write the html? Did you mean having the html itself written within the suitelet script? I'm curious as how the redirection would work from there, as I might need this for a later project.
b
Use file.load to load the html file, and then write to the suitelet's response using ServerResponse.write
you can have the suitelet do different things depending on the method of the request