https.post.promise “.then” not called

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.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');
}
Rookie Asked on July 15, 2020 in SuiteScript.

What do you see logged and so you see any further messages in the Chrome console?

on July 15, 2020.

Hello thanks for your response. If executing via pageInit (which is working) I can see .then and .catch executed right after post.promise, when I ran 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.

on July 15, 2020.
Add Comment
1 Answer(s)

Use more standard debugging techniques. The N/log module behaves unusually when used client side.  Logs used within the client script entry points will log to the client script. Logs used within the button will log to the  user event script. Promises appear to act a little weirdly in that the logs inside promises started from the client script enry point will go to the client script while the logs inside promises started from the button will not go to the user event script.

Use console.log (I like console.debug to better match log.debug) or at least use debugger; statements

Intermediate Answered on July 15, 2020.

Thanks for your response but it’s not just the logging I am trying to figure out. You’ll see on code that I have a function commented out.

});
//redirectAfterProcess(soId);
log.debug('CS - Inside Promise', 'Test');
 
})
When I un-comment it and execute via pageInit, that works, as well as the logs. So basically, nothing inside .then gets executed if it’s called from a button.
on July 15, 2020.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.
  • This site made possible by our sponsors:   Tipalti   Celigo   Limebox   Become a Sponsor