Sunday, March 31, 2019

Execute Script when Mark-All button is Clicked

Customer has a function that calculates a custom column in their end. This function works if the use will manually check Apply checkbox one-by-one. When user marks the items using Mark All button, the custom column was not set and was not calculated.  

(1) Create a client Script using this script:

function validateField(type,name,linenum)
{
 if(type == 'time' && name == 'apply')
 {
    var stApply = nlapiGetLineItemValue('time','apply',linenum);
   nlapiLogExecution('debug','stApply', stApply);
  if(stApply == 'T')
  {
   var oldRate = nlapiGetCurrentLineItemValue('time','rate');
   nlapiLogExecution('debug','oldRate', oldRate);
   nlapiSetCurrentLineItemValue('time','rate',100.00);
   var newRate = nlapiGetCurrentLineItemValue('time','rate');
   nlapiLogExecution('debug','newRate', newRate);
  }
 }
 return true;
}
(2) Deploy the created script in Invoice.
(3) Go to Transactions > Sales > Create Invoices > New
(4) Choose customer who has more than one Billable items/expenses/time
(5) Click Apply column of the first line.

Actual Result:
Functions are called, rate value changed.

(6) Go back to the Invoice > Click Billable items/expenses/time > Click Mark All button.

Actual Result:
No function is called, rate value not changed.

Expected Result:
Rate value should be changed. 

Solution:

Create a User-Event Script that will be executed before user submits the record. Using this function, we will be checking the value of the Apply column and then set 100 to rate column if checked.

function beforeRecordSubmit(){
// triggered in the beforeSubmit event
var rec = nlapiGetNewRecord();
var intCount = rec.getLineItemCount('time');

for(var x=0; x < intCount; x++){
 var stApply = nlapiGetLineItemValue('time','apply',x);
 if(stApply == 'T'){
   var newRate = 100.00;
   nlapiSetLineItemValue('time','rate',x, newRate);
 }

}

}

DISCLAIMER: The sample code described herein is provided on an "as is" basis, without warranty of any kind, to the fullest extent permitted by law. Netsuite Inc. does not warrant or guarantee the individual success developers may have in implementing the sample code on their development platforms or in using their own Web server configurations.

Netsuite Inc. does not warrant, guarantee or make any representations regarding the use, results of use, accuracy, timeliness or completeness of any data or information relating to the sample code. Netsuite Inc. disclaims all warranties, express or implied, and in particular, disclaims all warranties of merchantability, fitness for a particular purpose, and warranties related to the code, or any service or software related thereto.

Netsuite Inc. shall not be liable for any direct, indirect or consequential damages or costs of any type arising out of any action taken by you or others related to the sample code.

No comments:

Post a Comment