Infinite loop with alert() inside a fieldChanged() ClientScript (with Chrome only !)

Hi Everyone,

I have a strange behavior on a SuiteScript ClientScript.

Here is my code :

define([], function() {
    this._validateCouponCode = function() {
        if(this.fieldId !== ‘custentity_sdr_coupon_code’) return true;
        if(this.currentRecord.getText(‘custentity_sdr_coupon_code’).length < 5) {
            alert(‘You must enter a coupon of 5 CHAR’);
            return false;
        return true;
    this._disableCouponField = function() {
        if(this.fieldId !== ‘custentity_sdr_apply_coupon’) return;
            .getField({fieldId : ‘custentity_sdr_coupon_code’})
            .isDisabled = (!this.currentRecord.getValue(‘custentity_sdr_apply_coupon’));
                fieldId : ‘custentity_sdr_coupon_code’,
                value : ”,
                ignoreFieldChange : true
    return {
        // ENTRY POINT
        fieldChanged: function (context) {
            // declare useful references to the context Object
            this.currentRecord = context.currentRecord;
            this.fieldId = context.fieldId;
        validateField: function(context) {
            // declare useful references to the context Object
            this.currentRecord = context.currentRecord;
            this.fieldId = context.fieldId;
            var arrayOfFieldToValidate = [
            //return (arrayOfFieldToValidate.indexOf(false) === -1);
            return this._validateCouponCode();

But with Chrome only, I got an infinite loop of alert. I think this is because alert() method try to remove focus, and the validateField method is fired when the focus is removed from the field.

How can I solve that ?

I tested the script with IE and Firefox, even if the alert pop-out twice, it is not as disturbing than with Chrome.


Any help would be appreciate ?




Rookie Asked on November 27, 2019 in SuiteCloud.
Add Comment
1 Answer(s)
Best answer

I have not experienced this personally before and am not sure this would solve it, but you could try using dialog.alert   (/app/help/  via the N/ui/dialog  module replacing the native JavaScript alert with the stylized NetSuite equivalent.

Intermediate Answered on November 27, 2019.

Hey, thanks a lot ! Even if it is not the perfect solution (the user have to click two time on the “OK” button), it is acceptable (it does not looks like a  massive bug). Here the code I used : 

         ‘title’: ‘Data validation process’,
         ‘message’: ‘The coupon must have at least 5 character’
 }).catch(function () { return false });
console.log(‘*** pending user action’);

I’ll try to contact NetSuite for a more “suitable” solution.  

on November 27, 2019.

more “complete” dialog/ui based solution :

on November 27, 2019.
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   Become a Sponsor