0

Hello – I hope someone could provide some advise or feedback.

Summary: I am trying to create a custom button (UE script) on Sales Order record. That custom button executes a function from a client side script. The function (snippet below) uses https.post.promise. It calls a Suitelet that I will be using to process some backend logic.

Problem: The “.then” portion is not called/executed.

Notes:

  • Everything is working expect for .then part. The suitelet is called by the post
  • When I tried to call the same function on pageInit, the .then part is executing
  • I have used chrome’s javascript profiler as well and tried to compare both executions (by clicking button and pageInit). I can see that .then is being called when the snippet is executed via pageInit but is not executed, when clicking the button
    function createIntercoPo(soId){
        
        log.debug('CS - Create Interco PO', 'START ' + soId);
        
        var suiteletURL = url.resolveScript({
            scriptId: 'customscript_swx_sl_auto_ic_so_po',
            deploymentId: 'customdeploy_swx_sl_auto_ic_so_po',
        });

        log.debug('CS - Suitelet URL', suiteletURL);
        
        /*https.post({
            async: true,
            url: suiteletURL,
            body: {
                soId: soId
            },
            callback: function(response) {
                
                
                var result = JSON.parse(response.body);
                redirectAfterProcess(result, transId, transType, "generation");
            }
        });*/
                
        https.post.promise({
            url: suiteletURL,
            body: {
                soId: soId
            } 
        })
        .then(function (response){
            log.debug({
                title: 'Response',
                details: response
            });
            
            //redirectAfterProcess(soId);
            
            log.debug('CS - Inside Promise', 'Test');
        })
        .catch(function onRejected(reason) {
            log.debug({
                title: 'Invalid Request: ',
                details: reason
            });
        });
        
        log.debug('CS - Create Interco PO', 'END');
        
    }
  • Do you see anything in the developer console? Is the `catch()` clause triggered instead? – Evert Jul 15 '20 at 09:43
  • @Evert thanks for the quick response. If executing via pageInit (which is working) I can see then and catch excecuted right after post.promise, when I run javascript profiler. If executed via clicking the button, after post.promise, it does not show then and catch and jumps straight to the last debug. – Julian Concepcion Jul 15 '20 at 09:58
  • In my opinion promise is not suitable for event driven calls. Event driven call is not the same as time parallel/timer driven. – armagedescu Jul 15 '20 at 10:38

0 Answers0