Thursday, April 18, 2019

Prevent the system from partially fulfilling orders for certain customers until all items in the order are available on hand through scripting

There are instances where a user would like to prevent  fulfilling orders for certain customer unless all of the ordered items are available.

The said use case is not supported as of the the moment via the standard process.

As an alternate solution, create a Client Side script triggered on Save Record event, which returns 'false' value upon execution when an ordered item is not at hand, preventing the record from being saved.

Below is a sample script:

function checkIF(type){
        
        var cust = nlapiGetFieldValue('entity');
        nlapiLogExecution('DEBUG','entity', cust);
        
        if (cust == '7'||'6'||'34'){
                
                var lineItemCount = nlapiGetLineItemCount('item');
                nlapiLogExecution('DEBUG','lineItemCount', lineItemCount );
                
                for( var i=1; i<=lineItemCount; i++){
                        nlapiLogExecution('DEBUG','i', i);
                        
                        var itemOnhand = nlapiGetLineItemValue('item','onhand',i);
                        nlapiLogExecution('DEBUG','itemOnhand', itemOnhand);
                        
                        if(itemOnhand <= 0){
                                nlapiLogExecution('DEBUG','if2', 'entered');
                                return false;
                        }
                        
                        
                }
                
        }
        
        return true;
 
}

* Note that 7, 6 and 34 are customer internal IDs.

This solution is related to Enhancement 263114.

No comments:

Post a Comment