Accessing Record Data in a Suitelet Without Passing Parameters

When working with Suitelets in NetSuite, a common approach to pass data from a record to a Suitelet page is by sending it through URL parameters. However, there are situations where you might not want to expose data in the URL or you simply want a cleaner approach.

Luckily, there’s a way to access record data directly in the Suitelet popup without explicitly passing it as parameters. This can be done using the window.opener object in client-side JavaScript, which allows the Suitelet to communicate with the parent record page.

How It Works

  1. Inject a hidden HTML field with script logic
  2. We add an INLINEHTML field to the Suitelet form that automatically runs JavaScript when the Suitelet loads. This script reads field values from the parent record using window.opener.nlapiGetFieldValue().
  3. Pass the values to the Suitelet backend
  4. The script dynamically builds a hidden form with the extracted values and submits it to the Suitelet itself, making the data available on the server-side request.
  5. Send processed data back to the record
  6. Once the Suitelet finishes processing, it can push the results back into the parent record using window.opener.nlapiSetFieldValue().
form.addField({
    id: 'custpage_data_injector',
    label: 'Data Injector',
    type: serverWidget.FieldType.INLINEHTML
}).defaultValue = `
    <script>
        document.addEventListener('DOMContentLoaded', function () {
            try {
                var invJson = window.opener.nlapiGetFieldValue('custbody_jj_pieces_inventory_snapshot') || '[]';
                var existingJson = window.opener.nlapiGetFieldValue('custbody_jj_pieces_tracking_json') || '[]';


                var form = document.createElement('form');
                form.method = 'POST';
                form.action = window.location.href;


                form.innerHTML += "<input type='hidden' name='custpage_inventorydata_json' value='" + encodeURIComponent(invJson) + "' />";
                form.innerHTML += "<input type='hidden' name='custpage_existingdata_json' value='" + encodeURIComponent(existingJson) + "' />";


                document.body.appendChild(form);
                form.submit();
            } catch (e) {
                alert('Error loading inventory data from parent window.');
                console.error(e);
            }
        });
    </script>`;

And when you’re ready to send data back to the record:

context.response.write(`
    <script>
        window.opener.nlapiSetFieldValue(
            'custbody_jj_pieces_tracking_json',
            '${JSON.stringify(result).replace(/'/g, "'")}'
        );
        window.close();
    </script>`);


Leave a comment

Your email address will not be published. Required fields are marked *