Thursday, October 29, 2009

NetSuite Tip: How to do math in summarized saved searches

How do you calculate the difference between two columns in a summarized saved search. For example, if you had one column that showed the number of items on pending estimates and unapproved orders and another that showed the number of items on order, how could you determine whether you would run out? There are three methods:

1. Export to excel or have excel link to the csv version of the search as a datasource. You will usually need a macro however.

2. Create a suitelet or portlet to process the data and add the calculations.

3. Add scripting to the search itself. A text formula field can hold any value, including JavaScript. You can use this to embed a script that runs when the page loads and performs math on the results.



- Posted using BlogPress from my iPhone

3 comments:

Unknown said...

The question on the 3rd option would be : How to reference the values on the formula fields(totals) since the name is just formula(numeric). How you use this as variables in a javascript.

Mark Walker said...

The scripting refers to the cells by their ids. Here's a sample from a formula text field on a summarized search. The formula field is essentially a string between two single quotes with the code between script tags.

Note that the script loops through all of the records for each line, which is unnecessary overhead but manageable.

var restable=document.getElementById("div__bodytab");for(i=0;restable.rows[i]!=null;i++){thisRow=restable.rows[i];if(thisRow.cells[0].innerHTML.indexOf("edit")<0){for(ci=1;thisRow.cells[ci+1]!=null;ci++){setZero(thisRow.cells[ci])}thisRow.cells[3].innerHTML=thisRow.cells[1].innerHTML-thisRow.cells[2].innerHTML;}}function setZero(cell){if(isNaN(cell.innerHTML)){cell.innerHTML=0}}

Mark Walker said...

Here's that script again - the first version was truncated on some lines:

var restable=document.getElementById("div__bodytab");for(i=0;restable.rows[i]!=null;i++)
{
thisRow=restable.rows[i]; if(thisRow.cells[0].innerHTML.indexOf("edit")<0)
{
for(ci=1;thisRow.cells[ci+1]!=null;ci++)
{setZero(thisRow.cells[ci])}
thisRow.cells[3].innerHTML=thisRow.cells[1].innerHTML-thisRow.cells[2].innerHTML;
}
}

function setZero(cell)
{
if(isNaN(cell.innerHTML)){cell.innerHTML=0}
}