Calling a backend suitelet from a suitelet to handle exceeding of governance limit

A backend suitelet is called from main suitelet to handle exceeding of governance limit.

Main suitelet

let postData = {
              labelCounterValue: labelChunks[i].length,
              label: label,
              printString: printString[i],
              labelChunkLength: labelChunks.length,
              labelChunks: labelChunks[i],
              i: i
            };
            var response = https.post({
              url: 'https://1223378-sb1.extforms.netsuite.com/app/site/hosting/scriptlet.nl?script=5823&deploy=1&compid=1223378_SB1&ns-at=AAEJ7tMQhAvy0so7qggMPxFzfJDOCHt1hXDNggvgL6swZPGqo48',
              body: JSON.stringify(postData),
              headers: {
                'Content-Type': 'application/json',
                'Accept': 'application/json',
                'User-Agent': 'Mozilla/5.0'
              }
            });


            resultData = JSON.parse(response.body);

Backend suitelet

const { labelImage, labelText, code } = postLabel(labelValues, k, printString);

function onRequest(context) {
        try {
            if (context.request.method === 'POST') {
                try {
                    const requestData = JSON.parse(context.request.body);
                    const labelCounterValue = requestData.labelCounterValue;
                    const labelValues = requestData.label;
                    const printString = requestData.printString;
                    const labelChunks = requestData.labelChunks;
                    const labelTextArray = [];
                    const labelArray = [];
                    let labelCount = 0;
                    let totalRepeat = 0;
                    const repeat = {};
                    for (let k = 0; k < labelCounterValue; k++) {
                        const labelImageArray = [];
                        for (let x = 0; x < labelChunks[k]; x += 1) {
                            if (!repeat[labelCount]) repeat[labelCount] = 0;
                            const { labelImage, labelText, code } = postLabel(labelValues, k, printString);
                            if (code == 429) {
                                if (repeat[labelCount] > 1 || totalRepeat > 4) break;
                                const time = repeat[labelCount] === 1 ? 5000 : 1000;
                                waitTime(time);
                                x -= 1;
                                repeat[labelCount] += 1;
                                totalRepeat += 1;
                                continue;
                            }
                            labelImageArray.push(labelImage);
                            labelTextArray.push(labelText);
                            labelCount += 1;
                        }
                        labelArray.push(labelImageArray);
                    }


                    let result = {
                        labelTextArray: labelTextArray,
                        labelArray: labelArray,
                    }
                    //log.debug("result", result)
                    context.response.write({
                        output: JSON.stringify({
                            resultArray: result
                        })
                    });
                } catch (error) {
                    log.error({
                        title: 'Error Processing POST Request',
                        details: error.message
                    });
                    context.response.write({
                        output: JSON.stringify({
                            success: false,
                            message: 'Error processing request: ' + error.message
                        })
                    });
                }
            } else {
                context.response.write({
                    output: 'This Suitelet only handles POST requests.'
                });
            }
        }
        catch (e) {
            log.error("Error @ onRequest", e)
        }
    }

Following are the risk elements:

  • Values larger than 10 MB it will return the error.
  • Each Suitelet page can take maximum of 5 minutes of loading time. If more than that may cause error.
  • Maximum Browser loading time is 60 sec. If more than that may cause error.

Leave a comment

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