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);

 }

}

}

Leave a comment

Your email address will not be published. Required fields are marked *