Professional Documents
Culture Documents
Netsuite Formulas: Contributing Organizations
Netsuite Formulas: Contributing Organizations
http://tiny.cc/NSformula
Please feel free to “give back” and share some. Send your formula examples to dhynek@business-
fitness.com.
Contributing Organizations:
Table of Contents
Case When Formulas .................................................................................................................................... 4
Multiple Case When statements in a single formula ................................................................................ 4
Using Case When to locate text ................................................................................................................ 4
Using date in Case When .......................................................................................................................... 5
Case When with more than one select ..................................................................................................... 5
Multiple Case When statements with Wildcards ..................................................................................... 5
Case When statement to look up Multiple Zip Codes .............................................................................. 5
Using Case When to select all date for the last 7 days (Time for last week by employee) ...................... 5
Using Multiple “Not” in a Case When statement ..................................................................................... 5
Multiple Case When satements Grouped................................................................................................. 5
To display the milestone status with corresponding colors (red, yellow, green) ..................................... 5
Using Case When to determine when an item was sold for free ............................................................. 6
Mass Update for Last Sales Face to Face .................................................................................................. 6
Decode .......................................................................................................................................................... 6
Simple Case When with Decode ............................................................................................................... 6
Decode with Multiple Case When ............................................................................................................ 6
Look at date and determine the month ................................................................................................... 6
Dealing with Null Data .................................................................................................................................. 7
NVL ............................................................................................................................................................ 7
NVL2 .......................................................................................................................................................... 7
Use NVL2 to provide link when a field is not null ..................................................................................... 7
Nullif ......................................................................................................................................................... 7
Using SUM and Nullif to Divide 2 formulas… ............................................................................................ 7
Managing Text .............................................................................................................................................. 7
Remove characters from text ................................................................................................................... 7
Display only portion of text....................................................................................................................... 8
Concat ....................................................................................................................................................... 8
Concatenate two fields ............................................................................................................................. 8
Using CONCAT Statement ......................................................................................................................... 8
Using CONCAT Statement in a Mass Update Fields Formula.................................................................... 8
RPad/LPad ................................................................................................................................................ 8
SUBSTR...................................................................................................................................................... 8
Clean up Phone Numbers using “Replace” ............................................................................................... 9
Formatting .................................................................................................................................................... 9
Using check Box in a Formula and Inline HTML ........................................................................................ 9
Controlling Column and Row data in Searches ....................................................................................... 9
HTML Text Tags ......................................................................................................................................... 9
NetSuite Custom Label coding .................................................................................................................. 9
Formula Example: ............................................................................................................................... 10
Column Label Example: ....................................................................................................................... 10
Quick Links .................................................................................................................................................. 11
Using quick link pop-up for inline editing ............................................................................................... 11
Customer Quick View Link (Text Formula).............................................................................................. 11
Log a Call with loaded customer and contact information ..................................................................... 11
Log a Call with loaded customer, contact, and support contract information ....................................... 11
View Contracts ........................................................................................................................................ 12
Send Custom Email ................................................................................................................................. 12
Create a Deal ........................................................................................................................................... 12
View Activities ......................................................................................................................................... 12
Edit Customer ......................................................................................................................................... 12
Selecting an Email Template and assign Contact from a Link (Text formula)......................................... 12
Sending an Email from a transaction search (Text formula)................................................................... 12
Calculation Functions .................................................................................................................................. 13
Math ....................................................................................................................................................... 13
Show quantity within a range ................................................................................................................. 13
Calculate Gross Profit.............................................................................................................................. 13
Calculate Days to a Date ......................................................................................................................... 13
Calculate Days between Dates using System Notes ............................................................................... 13
Total sales ............................................................................................................................................... 13
Total Cost ................................................................................................................................................ 13
Gross Profit Dollars ................................................................................................................................. 14
Getting year to date (YTD) revenue in transaction search ..................................................................... 14
Calculate Subtotal ................................................................................................................................... 14
Date......................................................................................................................................................... 14
Used to calculate a date 60 days in the future ....................................................................................... 14
Show the day of the week ...................................................................................................................... 14
Using MAX with Date range to select Month range ............................................................................... 15
Using TO_CHAR to find last month in a date field .................................................................................. 15
Using the TO_CHAR to select data for a specific day of the week.......................................................... 15
Search to compare an Expiration date to today’s date .......................................................................... 15
Scripts ..................................................................................................................................................... 15
Sample Script (Work Flow Action Script) ................................................................................................ 15
Additional Script Example ....................................................................................................................... 16
Miscellaneous ............................................................................................................................................. 17
Using a MAX Command inside a formula (used in actual VRS Forecast) ................................................ 17
Who Last Modified .................................................................................................................................. 17
Search for a work for sequence in a field using REGEXP_INSTR ............................................................. 17
Not Equal To............................................................................................................................................ 17
Finding First not Null field from list of fields using Coalesce .................................................................. 17
Using an URL to Enter Data on an Online Form ...................................................................................... 17
Using a Saved Search to fill as a default value in field ............................................................................ 18
Using MAX and SUM in the same formula.............................................................................................. 18
Wildcards ................................................................................................................................................ 18
Case When Formulas
Multiple Case When statements in a single formula
CASE {custitemcommission_parent}when 'Autodesk Software Vertical' THEN 1 WHEN 'Autodesk
Software Vertical Subscription New' THEN 2 WHEN 'Autodesk Software Vertical Subscription Renewal'
THEN 3 WHEN 'Autodesk Software Horizontal' then 4 WHEN 'Autodesk Software Horizontal Subscription
New' then 5 WHEN 'Autodesk Software Horizontal Subscription Renewal' THEN 6 WHEN 'Hardware
Equipment ' THEN 7 WHEN 'Refurb Equipment' THEN 8 WHEN 'Hardware Maintenance Program' then 9
when 'Software -Non Autodesk' then 11 when 'Software - Kubotek' then 12 when 'Imaging Services - All
Formats' then 13 when 'InkJets' then 14 When 'Consulting' then 15 when 'Training' then 16 when
'Software Support' then 17 when 'Drafting Supplies' then 18 When 'S&R Parts & Labor' then 10 ELSE 0
END
Using Case When to select all date for the last 7 days (Time for last week by employee)
CASE WHEN ({today} - {time.date}) BETWEEN 0 AND 7 THEN {time.durationdecimal} end
To display the milestone status with corresponding colors (red, yellow, green)
CASE WHEN ({status} = 'Completed' OR ROUND({percentworkcomplete}*100, 1) = 100.0) THEN '<span
style="color:#afc437;font-weight:bold;">Completed</span>' WHEN (TO_DATE(TO_CHAR({startdate},
'MM/DD/YYYY'), 'MM/DD/YYYY') - TO_DATE(TO_CHAR(SYSDATE, 'MM/DD/YYYY'), 'MM/DD/YYYY')) < -
1 THEN '<span style="color:#bf340f;font-weight:bold;">' || (TO_DATE(TO_CHAR(SYSDATE,
'MM/DD/YYYY'), 'MM/DD/YYYY') - TO_DATE(TO_CHAR({startdate}, 'MM/DD/YYYY'), 'MM/DD/YYYY')) || '
days overdue</span>' WHEN (TO_DATE(TO_CHAR({startdate}, 'MM/DD/YYYY'), 'MM/DD/YYYY') -
TO_DATE(TO_CHAR(SYSDATE, 'MM/DD/YYYY'), 'MM/DD/YYYY')) = -1 THEN '<span
style="color:#bf340f;font-weight:bold;">' || (TO_DATE(TO_CHAR(SYSDATE, 'MM/DD/YYYY'), 'MM/DD/YYYY')
- TO_DATE(TO_CHAR({startdate}, 'MM/DD/YYYY'), 'MM/DD/YYYY')) || ' day
overdue</span>' WHEN (TO_DATE(TO_CHAR({startdate}, 'MM/DD/YYYY'), 'MM/DD/YYYY') -
TO_DATE(TO_CHAR(SYSDATE, 'MM/DD/YYYY'), 'MM/DD/YYYY')) = 0 THEN '<span
style="color:#f89406;font-weight:bold;">Due today</span>' WHEN (TO_DATE(TO_CHAR({startdate},
'MM/DD/YYYY'), 'MM/DD/YYYY') - TO_DATE(TO_CHAR(SYSDATE, 'MM/DD/YYYY'), 'MM/DD/YYYY')) =
1 THEN '<span style="color:#428bca;font-weight:bold;">Due in ' || (TO_DATE(TO_CHAR({startdate},
'MM/DD/YYYY'), 'MM/DD/YYYY') - TO_DATE(TO_CHAR(SYSDATE, 'MM/DD/YYYY'), 'MM/DD/YYYY')) || '
day</span>' ELSE '<span style="color:#428bca;font-weight:bold;">Due in ' ||
(TO_DATE(TO_CHAR({startdate}, 'MM/DD/YYYY'), 'MM/DD/YYYY') - TO_DATE(TO_CHAR(SYSDATE,
'MM/DD/YYYY'), 'MM/DD/YYYY')) || ' days</span>' END
Using Case When to determine when an item was sold for free
case when {item.custitemcommission_parent}='Software Support' and {amount}<1 then
{item.custitem_purchase_price}end
Decode
Simple Case When with Decode
Case {custeventcall_outcome} when 'Connect' then (DECODE (to_char({createddate}, 'D'), '2' , 1))end
(({billingtransaction.amount}-(NVL({billingtransaction.discountamount},0)))-(case
{item.custitemcommission_parent}when'Software Support' then ({billingtransaction.amount}*.5) when
'InkJets' then (case when {purchaseorder.amount}='0' then (NVL({item.lastpurchaseprice},0)*{quantity})
else {purchaseorder.amount} end) when'Training' then ({billingtransaction.amount}*.5)
when'Consulting' then ({billingtransaction.amount}*.5) when'Imaging Services - All Formats' then
({billingtransaction.amount}*.5) when'Hardware Maintenance Program' then
({billingtransaction.amount}*.7) Else {purchaseorder.amount} end))*{contribution}
NVL2
Use NVL2 to provide link when a field is not null
NVL2({custbody_ec_mg_contracts_billing},('<a name="Edit"
id="Edit"href="'||'https://system.netsuite.com/app/common/custom/custrecordentry.nl?rectype=215
&id='||{custbody_ec_mg_contracts_billing.internalid}||'&e=f"target="_blank">EContract</a>'),'1')
Nullif
Using NULLIF compares expr1 and expr2. If equal, the function returns null. If not equal, the function
returns expr1.
NULLIF(({billingtransaction.amount}-(NVL({billingtransaction.discountamount},0)))-(case
{item.custitemcommission_parent}when'Software Support' then ({billingtransaction.amount}*.5) when
'InkJets' then (case when {purchaseorder.amount}='0' then (NVL({item.lastpurchaseprice},0)*{quantity})
else {purchaseorder.amount} end) when'Training' then ({billingtransaction.amount}*.5)
when'Consulting' then ({billingtransaction.amount}*.5) when'Imaging Services - All Formats' then
({billingtransaction.amount}*.5) when'Hardware Maintenance Program' then
({billingtransaction.amount}*.7) Else {purchaseorder.amount}
end),0)/NULLIF(({billingtransaction.amount}-(NVL({billingtransaction.discountamount},0))),0)
Managing Text
Remove characters from text
Provided By Danielle Tourdot from WiscNet: I recently needed to remove the first 3-5 characters from
our Transport Provider ID to only give the name of the Transport Provider. Here is the formula that I
used:
case when {custrecord_transport_provider_id} like '%' then
(SUBSTR({custrecord_transport_provider_id},INSTR({custrecord_transport_provider_id},' ')+1)) else
{custrecord_transport_provider_id} end
Concat
Concatenate two fields
Provided by Lisa Lijewski from Cielo: When you have multiple lines on one record, concatenate the internal
ID and the Line no. for a unique identifier (to be able to upload/update each individual line on a record).
{internalid} || {line}
RPad/LPad
The RPAD and LPAD allows you to remove characters from a string at a specific point and direction for
Example LPAD(‘tom’, 2) will return ‘to’. RPAD removes from the Right and LPAD from the Left.
rpad({item.displayname},60) will display only the first 60 characters.
SUBSTR
The SUBSTR allows you to show characters after a point in the verbiage
Example:
Created From Field returns result: Purchase Order #PO12345, only want to see PO12345
The total characters from the beginning of the field info to where the PO starts is 16 characters
case when {type}='Purchase Order' then (substr({createdfrom},17)) end
***Had to add an additional character count to have the # remove from the verbiage
Provided by Lisa Lijewski from Cielo: Change the posting/accounting period into a three-digit month
format
SUBSTR({postingperiod},1,3)
Provided by Lisa Lijewski from Cielo: Extract a substring from a string using expression pattern
matching. This one gives us the customer name (entity field) from the beginning of the string up to the
colon (as we use customer: project hierarchy, but want parent customer for reporting). Good for when
the (no hierarchy) is not available on a search field.
RTRIM(REGEXP_SUBSTR({entity},'[^:]*'))
Formatting
Using check Box in a Formula and Inline HTML
Case when {custrecord_hw_top_customer}=’T' then '<span style="font-family:Times;font-size:22px;font-
style:normal;font-weight:bold;text-decoration:none;text-transform:none;color:33cc33;background-
color:ffffff;">Imaging Top Customer </span>' else (Case when {custrecord_curr_custom_tier}='MG
TOP 200'then '<span style="font-family:Times;font-size:22px;font-style:normal;font-weight:bold;text-
decoration:none;text-transform:none;color:33cc33;background-color:ffffff;">MG TOP 200
</span>' end) end
"href="https://system.netsuite.com/app/crm/common/crmmessage.nl?&contact='||{custrecordlead_c
ontact_ref.internalid}||'&entity='||{custrecordlead_customer_ref.internalid}||'&record='||{internalid}
||'&recordtype=272&xnew=T&l=T&templatetype=EMAIL&template=1162&cf=65"target="_blank">Sen
d Welcome Email</a>'),'Fix Contract Details<BR> <------- ')),'<b>Need</b> to Fix <BR> Contact
Ref')
Log a Call with loaded customer, contact, and support contract information
'<a name=" Log Call " id=" Log Call
"href="'||'https://system.netsuite.com/app/crm/calendar/call.nl?status=COMPLETE&l=T&refresh=activi
ties&invitee='||{internalid}||'&company='||{custrecord_customer.internalid}||'&contact='||{custrecor
d_contact.internalid}||'&pf=custevent_supp_cont&pi='||{internalid}||'&cf=309"target="_blank">Log
Call</a>'
View Contracts
'<a name="Contracts"
id="Contracts"href="https://system.netsuite.com/app/common/search/searchresults.nl?rectype=105&s
earchtype=Custom&ADW_Entity_INTERNALID='||{custrecord_customer2.internalid}||'&sortcol=CUSTR
ECORD_EXP_DATE_raw&sortdir=ASC&csv=HTML&OfficeXML=F&pdf=&style=NORMAL&report=&grid=&
searchid=2995&dle=T"Target="_blank">Contracts</a>'
Create a Deal
'<a name="Create Deal" id="Create
Deal"href="'||'https://system.netsuite.com/app/accounting/transactions/estimate.nl?entity='||{Custo
mermain.internalid}||'&cf=217"target="_blank">Create Deal</a>'
View Activities
'<a name="Activites"
id="Activities"href="'||'https://system.netsuite.com/app/crm/common/crmactivityhistory.nl?id='||{cus
tomer.internalid}||'&fkcol=kCompany"target="_blank">Activities</a>'
Edit Customer
'<a name="Edit"
id="Edit"href="'||'https://system.netsuite.com/app/common/entity/custjob.nl?id='||{custrecord_ec_c
_customer.internalid}||'&cf=63&e=T"target="_blank">Edit</a>'
Selecting an Email Template and assign Contact from a Link (Text formula)
'<a name="Send Email Custom" id=" Send Email Custom
"href="https://system.netsuite.com/app/crm/common/crmmessage.nl?&contact='||{custrecordec_ma
nager_contact.internalid}||'&entity='||{custrecord_ec_c_customer.internalid}||'&record='||{internalid
}||'&recordtype=215&xnew=T&l=T&templatetype=EMAIL&template=476&cf=65"target="_blank">Send
Email FSMA</a>'
Sending an Email from a transaction search (Text formula)
'<a name="Send Email" id=" Send Email
"href="https://system.netsuite.com/app/crm/common/crmmessage.nl?transaction='||{internalid}||'&e
ntity='||{customer.internalid}||'&l=T&templatetype=EMAIL"target="_blank">Send Email</a>'
Calculation Functions
Math
Show quantity within a range
Provided by Jenny Berg from Forte Research: To show the number of employees in each age range
group
CASE WHEN (ROUND(ROUND({today}-{birthdate},2)/365)) between '1' and '19' THEN 'Under 20' WHEN
(ROUND(ROUND({today}-{birthdate},2)/365)) between '20' and '24' THEN '20-24' WHEN
(ROUND(ROUND({today}-{birthdate},2)/365)) between '25' and '29' THEN '25-29' WHEN
(ROUND(ROUND({today}-{birthdate},2)/365)) between '30' and '34' THEN '30-34' WHEN
(ROUND(ROUND({today}-{birthdate},2)/365)) between '35' and '39' THEN '35-39' WHEN
(ROUND(ROUND({today}-{birthdate},2)/365)) between '40' and '44' THEN '40-44' WHEN
(ROUND(ROUND({today}-{birthdate},2)/365)) between '45' and '49' THEN '45-49' WHEN
(ROUND(ROUND({today}-{birthdate},2)/365)) between '50' and '54' THEN '50-54' WHEN
(ROUND(ROUND({today}-{birthdate},2)/365)) between '55' and '59' THEN '55-59' WHEN
(ROUND(ROUND({today}-{birthdate},2)/365)) between '60' and '64' THEN '60-64' WHEN
(ROUND(ROUND({today}-{birthdate},2)/365)) between '65' and '69' THEN '65-69' WHEN
(ROUND(ROUND({today}-{birthdate},2)/365)) between '70' and '74' THEN '70-74' WHEN
(ROUND(ROUND({today}-{birthdate},2)/365)) between '75' and '79' THEN '75-79' WHEN
(ROUND(ROUND({today}-{birthdate},2)/365)) between '80' and '84' THEN '80-84' WHEN
(ROUND(ROUND({today}-{birthdate},2)/365)) between '85' and '89' THEN '85-89' ELSE NULL END
case when {entitystatus}='Closed Won' then ((case when {systemnotes.newvalue}='Closed Won' then
{systemnotes.date} end)-{datecreated})end
Total sales
nvl((case when {Type}='Credit Memo' then (({amount}-(NVL({discountamount},0)))*{contribution}) else
(({billingtransaction.amount}-(NVL({billingtransaction.discountamount},0)))*{contribution})end) ,(case
when {Type}='Credit Memo' then (({amount}-(NVL({discountamount},0)))*1) else
(({billingtransaction.amount}-(NVL({billingtransaction.discountamount},0)))*1)end))
Total Cost
(case {item.custitemcommission_parent}when'Software Support' then ({billingtransaction.amount}*.4)
when 'InkJets' then (case when {purchaseorder.amount}='0' then
(NVL({item.lastpurchaseprice},0)*{quantity}) else {purchaseorder.amount} end) when'Training' then
({billingtransaction.amount}*.4) when'Consulting' then ({billingtransaction.amount}*.4) when'Imaging
Services - All Formats' then ({billingtransaction.amount}*.5) when'Hardware Maintenance Program'
then ({billingtransaction.amount}*.7) when'Software - Kubotek' then ({billingtransaction.amount}*.8)
Else {purchaseorder.amount} end)*{contribution}
Calculate Subtotal
nvl2({netamountnotax},{netamountnotax},{amount})
Date
Used to calculate a date 60 days in the future
{today}+60
Using the TO_CHAR to select data for a specific day of the week
case when to_char({time.date},'D')='1' then {time.durationdecimal} end = Sunday
case when to_char({time.date},'D')='2' then {time.durationdecimal} end = Monday
Scripts
Sample Script (Work Flow Action Script)
This script sample is used to update a field on the customer from a Custom Record workflow. A
Workflow Action script allows you to run a script within a workflow. This function allows you to update
associated records from a workflow, this is very handy to “Carry Data Forward”
//**Formula to write data from a contracts workflow to the attached Customer record **
//***In order to create a WorkFlow Action, you need 3 netsuite objects, first the physical script (the
code), second is the SCRIPT Record in netsuite, this is where you connect the script to a function
(Contracts_Customer), and lastly you need a SCRIPT DEPLOYMENT record. Example of this in NS:
Physical script us "Preview masterGraphics.js", SCRIPT Record is "Master G - Test Tom" (This is also the
name of WorkFlow Action) and the SCRIPT DEPLOYMENT "Customdeploy1" This sample workflow is
designed to work from a CustomRecord (Contrats) to a Customer, thus the fields are noted from the
CustomRecord standpoint ***
function Evolve_Contracts_Customer(){
// Getting the data / values needed
var custRec = nlapiGetFieldValue('custrecord_customer');
var custName = nlapiGetFieldValue('name');
var expdate = nlapiGetFieldValue('custrecord_exp_date');
//Combining the data into a single Variable
var data = (custName + " EXP: " + expdate)
//Selecting the Record Type that will be updated
var recId = nlapiLoadRecord('customer',custRec);
//Writing the field value
recId.setFieldValue('custentity_training_sub_end',data);
//Submitting / Saving the Record
var rec = nlapiSubmitRecord(recId);
}
// Script End
Build workflow and set new action as the name of the script
Miscellaneous
Using a MAX Command inside a formula (used in actual VRS Forecast)
MAX(case {item.custitem_commission_code}when '1' then {salesrep.custentity_p_1_q1} when'2' then
{salesrep.custentity_p_2_q1} when'3' then {salesrep.custentity_p_3_q1} when'16' then
{salesrep.custentity_p_16_q1} when'15' then {salesrep.custentity_p_15_q1} when'17' then
{salesrep.custentity_p_17_q1} when'13' then {salesrep.custentity_p_13_q1} when'9' then
{salesrep.custentity_p_9_q1} when'7' then {salesrep.custentity_p_7_q1} when'4' then
{salesrep.custentity_p_4_q1} when'5' then {salesrep.custentity_p_5_q1} when'11' then
{salesrep.custentity_p_11_q1} when '8' then {salesrep.custentity_p_8_q1} when '14' then
{salesrep.custentity_p_14_q1} end)
Not Equal To
case when ({type}='Deal' and ({status}<>'Processed') and {custbody20}='Lost Deal') then {internalid}end
Finding First not Null field from list of fields using Coalesce
You can use the function Called Coalesce to search a list of fields and then write the first not Null value.
Used this in a Workflow that was looking at 3 date fields, we need to find a field that was not null then
write the date.
COALESCE({custrecord_asset_expire},{custrecord_exp_date}, {custrecord6})
https://forms.netsuite.com/app/site/crm/externalcustrecordpage.nl?compid=652186&formid=212&h=
e4257034c558ffb566a1&redirect_count=1&did_javascript_redirect=T&custrecordlead_source=SAMPLE
Note: If you are using a field that is list value you need to use the internal ID for the value you want
selected.
Wildcards
case when {transaction.item} like '%Imag%' then 'Yes' end