Tuesday, September 25, 2018

Deleting Line Items upon Firing Page Init Event on Edit Mode

Question: How to implement a Client Side Script that would delete certain line items on a sales order record when the Page Init event executes. In this case, a custom Transaction Column Field is used to determine if a line item needs to be deleted. Custom Transaction Column Field is of checkbox type.
1. Create a simple Client Side Script by navigating to Customization > Scripting Scripts > New.
2. Click Client link.
3. Make sure you have a custom Transaction Column Field applied to the sales order record. You can create one by navigating to Customization > Lists, Records, & FieldsTransaction Column Field > New.
4. Create a javascript file by using any text editor and your script should contain this function:
function deleteLineItemsOnPageInit(type){
 if (type == 'edit') {  
  var itemCount = nlapiGetLineItemCount('item');
            for (var i = itemCount; i>0; i--) {
               window.isinited = true;
               nlapiSelectLineItem('item', i);
               var itemLineCB = nlapiGetCurrentLineItemValue('item', 'custcol7');
               if(itemLineCB == 'T'){ 
                window.isinited = true;  

4. Upload your Script on the Client Side Script you have created in step 1 and specify the function name: deleteLineItemsOnPageInit.

No comments:

Post a Comment