I have a button on a case record that, using a Cli...
# suitescript
s
I have a button on a case record that, using a Client script with the https.requestSuitelet.promise() method, runs a Suitelet in the background that creates a quote. I am testing this in sandbox, and I get a Failed: {"type":"error.SuiteScriptError","name":"SSS_REQUEST_TIME_EXCEEDED"} error on the Client script for the first one I do of the day. It takes around 25 seconds to get this response back, but my quote is still created. Any tests after that work as intended and it takes about 15 seconds for it to complete. Is there a reason why it only errors out on that first one? Is there something I can do to mitigate that error?
Copy code
function startQuoteSuitelet() {
    return logErrorIfNeeded("startQuoteSuitelet", function () {
          log.debug("Create Quote button clicked");

          //get case info
           var currentRecObj = currentRecordMod.get();
           var caseId = currentRecObj.id;

           //show message that national accounts quote is being created
           var startQuoteMessage = message.create({
                    ...
           });
           startQuoteMessage.show();

           //start creating quote with backend suitelet
           https.requestSuitelet.promise({
               scriptId: 'customscript_lx_sl_na_quote_creation',
               deploymentId: 'customdeploy_lx_sl_na_quote_creation',
               urlParams: {
                        'custparam_case_id': caseId
               }
           })
               .then(function (result) {
                   console.log("Completed: " + result.body);
                   startQuoteMessage.hide();
                   var endQuoteMessage = message.create({
                            ...
                   });
                   endQuoteMessage.show(10000);
                   var responseBody = JSON.parse(result.body);
                   var quoteUrl = url.resolveRecord({
                       recordType: 'estimate',
                       recordId: responseBody.quoteId,
                       isEditMode: false
                   });
                   window.open(quoteUrl);
               })
               .catch(function (reason) {
                   console.log("Failed: " + reason);
                   var errorQuoteMessage = message.create({
                            ...
                   });
                   errorQuoteMessage.show();
               })
          })
      }
Copy code
const onRequest = (context) => {
            try {
                log.debug({ title: 'Request received...' });
                var quoteId = createQuote(context);
                context.response.setHeader({name: 'Content-Type', value: 'text/plain'});
                context.response.write(JSON.stringify({quoteId: quoteId}));
            } catch (e) {
                log.error("error", e)
            }
        }

        function createQuote(context) {
            var caseRecord = record.load({
                type: record.Type.SUPPORT_CASE,
                id: context.request.parameters.custparam_case_id
            });

            var quoteRecord = record.create({
                type: record.Type.ESTIMATE,
                isDynamic: true
            });

            //set quote fields
            quoteRecord.setValue({
                fieldId: 'customform',
                value: 303
            });

            ...

            var sublistName = 'recmachcustrecord_na_case';

            var itemLineCount = caseRecord.getLineCount({
                sublistId: sublistName
            });

            for (var i = 0; i < itemLineCount; i++) {
                //get case fields
                var itemSKU = caseRecord.getSublistValue({
                    sublistId: sublistName,
                    fieldId: 'custrecord_na_item',
                    line: i
                });

                ...

                //add line
                quoteRecord.selectNewLine({ sublistId: 'item' });

                //set item
                quoteRecord.setCurrentSublistValue({ sublistId: "item", fieldId: "item", value: itemSKU, forceSyncSourcing: true });

                ...

                //commit line
                quoteRecord.commitLine({ sublistId: 'item' });
            }
            var quoteId = quoteRecord.save();
            return quoteId;
        }