'How to make pop up when client has used 75% of their credit limit in netsuite

I am very new to javascript in Netsuite or workflow. i would like to make pop up when the credit limiet is used 75% then this will pop up when we make sales order. can anyone help me for the formula?



Solution 1:[1]

A sample Client Script to meet your requirements is below with comments as to what each step does. Don't forget to upvote if you find this helpful.

More information can be found in SuiteAnswer: Client Scripts, fieldChanged function, saveRecord function, and N/record module.

/**
 * scriptName.js
 * @NApiVersion 2.0
 * @NScriptType ClientScript
 */

define(['N/currentRecord', 'N/record'], function(currentRecord, record){
    function fieldChanged(context){
        //after the Customer field value is selected
        if (context.fieldId === 'entity'){
            //get the current/SO record
            var soRec = context.currentRecord;
            //get customer id
            var customerId = soRec = record.getValue({fieldId: 'entity'});
            //get customer record
            var customerRec = record.load({type: record.Type.CUSTOMER, id: customerId});
            //get customer's credit limit and balance
            var creditLimit = customerRec.getValue({fieldId: 'creditlimit'});
            var customerBalance = customerRec.getValue({fieldId: 'balance'});
            //evaluate if 75% condition is met
            var testValue = Number(customerBalance)/Number(creditLimit);
            if(Number(testValue) >= .75){
                //if condition is met display message
                alert("Customer Balance/Credit Limit is >= 75%");
            }
        }
    }
    function saveRecord(context){
        //this function can be used to disallow saving of the new SO if credit limit is within 75%
        
        //get the current/SO record
        var soRec = context.currentRecord;
        //get customer id
        var customerId = soRec = record.getValue({fieldId: 'entity'});
        //get customer record
        var customerRec = record.load({type: record.Type.CUSTOMER, id: customerId});
        //get customer's credit limit and balance
        var creditLimit = customerRec.getValue({fieldId: 'creditlimit'});
        var customerBalance = customerRec.getValue({fieldId: 'balance'});
        //evaluate if 75% condition is met
        var testValue = Number(customerBalance)/Number(creditLimit);
        if(Number(testValue) >= .75){
            alert("You cannot save this record. Customer Balance/Credit Limit is >= 75%");
            return false; //do not allow save
        }
        else{
            return true; //allow save
        }
    }
    return {
        fieldChanged: fieldChanged,
        saveRecord: saveRecord
    }
});

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Martha