Sunday, May 12, 2019

How To Disable a Line Item Field for specific line items using nlapiDisableLineItemField?

Using nlapiDisableLineItemField will disable or enable a line item field for every single line items.

If users wants to only disable/enable line item fields on a per-item basis, they will need to use the Line Init Function of the Client Side Script.

Sample code below:

function lineInit(){
 var itemdesc = nlapiGetCurrentLineItemValue('item', 'description');
   
 if (itemdesc == '')
 {
  nlapiDisableLineItemField('item', 'custcol1', true);
 }
 else
 {
  nlapiDisableLineItemField('item', 'custcol1', false);
 }
}

1. Navigate to Customization > Scripting > Scripts > New > Client Side Script.
2. Enter a name for the Client Side Script
3. Upload the script above
4. Enter lineInit in the Line Init Function
5. Save & Deploy
6. On the Script Deployment:
    - Applies To: Sales Order
    - Status: Testing
    - Log Level: Debug
7. Save

The above script will disable the custom line item field (id: custcol1) if item description is blank. If item description is not empty, then it will enable custcol1.

No comments:

Post a Comment