0
var formData = new FormData();
 formData.append("name", "John");
 formData.append("age", "31");
 for (var value of formData.values()) {
             log.debug(value); 
                }

but when i want to log form values using formData api. It's giving below error.
ReferenceError: "FormData" is not defined.

Salman
  • 333
  • 4
  • 18
  • Is that the exact error message? I ask because you show that you used "formData" and the error shows "FormData". Those are not the same variable. Maybe you accidentally capitalized an "F" elsewhere in the code? – w3bguy Sep 14 '17 at 11:20
  • Basically i am working on userevent script when click button it doesn't process data and shows error on web page Exact error is given below org.mozilla.javascript.EcmaError: ReferenceError: "FormData" is not defined. – Salman Sep 14 '17 at 11:31
  • Did you search your code for "FormData" instead of "formData"? – w3bguy Sep 14 '17 at 11:48
  • yes i have searched it and here formData is just a variable. I think netsuite not support FormData api. check the below links it's about Formdata() https://developer.mozilla.org/en-US/docs/Web/API/FormData/FormData http://www.javascripture.com/FormData – Salman Sep 14 '17 at 12:00
  • Well, you've now mentioned three different variables. formData, FormData and Formdata are all different. Case counts... ;) Try using the build in forms instead. NetSuite has stated many times that they do not actually support anything external. https://system.na1.netsuite.com/app/help/helpcenter.nl?fid=section_4325835149.html – w3bguy Sep 14 '17 at 12:37

1 Answers1

4

FormData is a client side API managed under XMHttpRequest

UserEvent scripts are server side scripts with no browser based APIs available at all.

So you could use FormData in a client script to send info to a Suitelet or RESTlet but it's not present in a UserEvent script.

If you want to create a form in a Suitelet using SS2.0 you can use the following as a sample:

/**
 *@NApiVersion 2.x
 *@NScriptType Suitelet
 */
define(["N/log", "N/redirect", "N/runtime", "N/ui/serverWidget", "N/url", "./kotnRECBCFilters"], 
    function (log, redirect, runtime, ui, url, kotnRECBCFilters_1) {
    function showPropertiesForm(context) {
        var form = ui.createForm({
            title: 'Property Trust Ledger'
        });
        var req = context.request;
        var fromLoc = form.addField({
            id: 'custpage_loc',
            type: ui.FieldType.SELECT,
            label: 'For Property',
            source: 'location'
        });
        fromLoc.updateLayoutType({ layoutType: ui.FieldLayoutType.NORMAL });
        fromLoc.updateBreakType({ breakType: ui.FieldBreakType.STARTCOL });
        if (req.parameters.custpage_loc) {
            fromLoc.defaultValue = req.parameters.custpage_loc;
        }
        var notAfterDate = form.addField({
            id: 'custpage_not_after',
            type: ui.FieldType.DATE,
            label: 'On or Before'
        });
        if (req.parameters.custpage_not_after) {
            notAfterDate.defaultValue = req.parameters.custpage_not_after;
        }
        form.addSubmitButton({
            label: 'Get Detail'
        });

        //... bunch of stuff removed

        context.response.writePage(form);
    }

    function onRequest(context) {
        if (context.request.method === 'POST') {
            var currentScript = runtime.getCurrentScript();
            var params = {};
            for (var k in context.request.parameters) {
                if (k.indexOf('custpage_') == 0 && k.indexOf('custpage_transactions') == -1) {
                    if ((/^custpage_.*_display$/).test(k))
                        continue;
                    params[k] = context.request.parameters[k];
                }
            }
            redirect.toSuitelet({
                scriptId: currentScript.id,
                deploymentId: currentScript.deploymentId,
                parameters: params
            });
            return;
        }
        showPropertiesForm(context);
    }
    exports.onRequest = onRequest;
});
bknights
  • 14,408
  • 2
  • 18
  • 31