Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Revision History
Page 1
Table of Contents
Table of Contents....................................................................................................................................... 2
1. Overview................................................................................................................................................ 3
Figure 1........................................................................................................................................ 4
Figure 2........................................................................................................................................ 4
Figure 3........................................................................................................................................ 5
Figure 4........................................................................................................................................ 5
Figure 5........................................................................................................................................ 6
Figure 6........................................................................................................................................ 7
2.5. Comments...................................................................................................................................... 7
Figure 7........................................................................................................................................ 7
2.6. Declarations.................................................................................................................................... 7
Figure 8........................................................................................................................................ 7
Figure 9........................................................................................................................................ 8
Figure 10................................................................................................................................... 10
Figure 11.................................................................................................................................... 12
This standard will be supported by a peer-review process prior to full customer release. This
process will ensure that the standards are being adhered to and that the code is understandable
and maintainable on an on-going basis.
/********************************************************************
* Name: The name of the script – script.js
* Script Type: Type of deployment, e.g. Client, Suitelet
*
* Version: 1.0.1 – 12/12/2012 – 1st release - JM
* 1.0.2 – 24/12/2012 – bug 121 resolved - AC
* 1.0.3 – 03/05/2013 – added expense calculation - PA
* 1.0.4 – 12/12/2014 – resolved bug 900 – JM
*
* Author: FHL
*
* Purpose: A description of the purpose of this script,
* together with its method of deployment.
*
* Script: The script record id – custscript_script
* Deploy: The script deployment record id – customdeploy_script
*
* Notes: If the script is linked to a form and other Dependencies
*
* Library: library.js
*******************************************************************
• The version history should reflect the general changes made, when they were made and
who made the changes. If several changes are being made at the same time – use
version number 1.
Page 3
Figure 1
/**
*
* Page Initialise
*
* @param startDate (start date of contract)
* @param endDate (end date of contract)
* @returns {date}
*
* 1.0.4 resolved bug 900
*
*/
• The naming of Files, Folders, Saved Searches, Custom Forms and the like should
reflect its purpose. (Figure 2)
Figure 2
To create a name for a Saved search for ‘Customers called Dave’
Incorrect My search
Dave
SEARCH DAVE
• Custom Id’s should start with an underscore and be written in lowercase. (Figure 3)
Page 4
Figure 3
To create an id for a Saved Search called ‘Customers called Dave’
Correct _customerscalleddave
Incorrect _customers_caled_dave
_Customers_Called_Dave
_CUSTOMERS_CALLED_DAVE
_CUSTOMERSCALLEDDAVE
_CustomersCalledDave
Figure 4
Variable Constant
Var EXCHANGE_RATE
• Do not create two elements that differ only by case and avoid using the same
name for variables and functions.
• Script & deployment id's should use the scripts name after the _.
“custscript_transformSO”
“customdeploy_transformSO”
Page 5
Figure 5
Correct if (i == exchangeRate)
{
foreignAmount = 1;
}
switch (exchangeRate)
{
case 1:
foreignAmount = 2;
break;
case 2:
foreignAmount = 6;
break;
}
switch (exchangeRate)
{
case 1:
foreignAmount = 2;
break;
case 2:
foreignAmount = 6;
break;
}
• For compound statements (if, for loops, switch blocks), open braces should be on
the line following the statement that begins a block.
• To aid readability try to keep code from straying outside the visible windowls.
Page 6
Figure 6
2.5. Comments
• Comments should be used to enhance the reader’s understanding of the code with
respect to its intention, algorithmic overview, and/or logical flow.
• The double slash (‘//’) style of comment tags are preferred over the /* */ syntax, with
the exception of file and function headers.
Figure 7
Function()
{
//Declarations
//Process
//Return
}
2.6. Declarations
• All variables should be declared using the ‘var’ keyword prior to use, to minimise
overheads in traversing the scope.
Figure 8
Page 7
2.7. Error Handling
• All functions should handle errors by using the ‘try…catch’ statement.
• During an error condition the error should be written to the NetSuite script
deployment using nlapiLogExecution. (Figure 9)
• All debug log executions should be removed prior to release.
Figure 9
try
{
// Run some code here
}
catch(e)
{
//Handle errors here
errorHandler(‘error message’, e);
}
Page 8
2.9. General Principles
There are a number of general principles that developers should adhere to in order
to promote code re-use, code readability and to promote code that is easy to service:
• Each line of code should be one statement – avoid performing multiple instructions
per line of code.
• Code should be structured in such a way as to ensure there is only one exit point.
• If a line of code spans more than the readable width of the screen, split it.
• Always use a string to populate a date field and not the NetSuite date conversion
function. E.g. - nlapiDateToString( date, dateFormat)
• Numeric values retrieved from NetSuite must be immediately parsed before any
calculations using FHLParseFloat(value) or FHLParseInt(value)
Page 9
2.10 Script Template
This is an example template that should be used at the start of any script file.
(Figure 10)
Figure 10
/*************************************************************************************
* Name: [todo]
* Script Type: [todo]
*
* Version: [todo]
*
* Author: [todo]
*
* Purpose: [todo]
*
* Script: [todo]
* Deploy: [todo]
*
* Notes: [todo - deployment details i.e. form associated etc]
*
* Library: [todo]
*************************************************************************************/
/**
* scriptTemplate
*/
function scriptTemplate()
{
initialise();
process();
}
/**
* initialise
*/
function initialise()
{
try
{
}
catch(e)
{
errorHandler("initialise", e);
}
}
/**
* main process
*/
function process()
{
try
{
}
catch(e)
{
errorHandler("process", e);
}
}
Page 10
3.0 Installing SuiteCloud IDE
Page 11
4.0 Installing Subversion (SVN) on SuiteCloud
Figure 11
Page 12
5.0 Programming Standards Update
1. All code must conform to the standards as it as being written, rather than amending it to fit the
standards when it is complete and submitted to the repository.
2. Developers should not introduce personal standards when writing code, especially when naming
conventions are introduced.
3. camelBack should be applied to all naming conventions excluding script and deployment names
& constant variables. Please note this refers to using lower camelBack.
Correct lowerCamelBack
Incorrect LowerCamelBack
lowercamelcase
4. Only use underscores to separate the NetSuite prefix to the script/deployment name. It should
not be used anywhere else.
Correct customscript_salesorderxml
Incorret customscript_tibco_salesorder_xml
5. Do not prefix the script/deployment name with the script type as it should be named solely after
the purpose.
Correct customdeploy_listpriceengine
Incorrect customdeploy_usereventlistpriceengine
6. The script name and deployment ID should always be the same, however this does not apply to
scripts that have multiple deployments. In cases of multiple deployments, take the context of its
purpose into account whilst naming.
Correct customdeploy_vatengineevents
customdeploy_vatenginetibco
customdeploy_vatenginesalesorder
Incorrect customdeploy_vatengine1
customdeploy_vatengine2
customdeploy_vatengine3
Page 13
7. Variables and any custom elements within NetSuite such as: custom record sets, entity fields
and transaction column/body fields should not contain a prefix.
8. If numerous amendments are being made to a piece of code during a short space of time,
ensure that the same version number is used. Follow this rule on a case by case basis.
_______________________
1.0.1 – 18/11/13 JM
1.0.2 – 18/11/15 JM
1.0.2 – 19/11/13 JM
9. Ensure to add header and function blocks containing the version number and the changes made
to the script if you are amending code that has been written pre standards or by a third party.
10. When making amendments to an old script, ensure you avoid overcomplicating it by minimising
the changes you include within the pre-existing code. Introduce a function to handle the
modifications outside.
Correct code
call function
code
function
Incorrect Code
↑
function
↓
code
Page 14