In this article, I will start looking at the syntax of the language and the different objects available.
BUT – The objects that are available to us depend on where the code is run.
- In an ASP Page
- In the Browser
- ‘Inside’ the Application server as Internal Script
This means that
- Objects that exist in the browser will not exist in ASP pages
- Objects that exist in ASP page will not exist in Internal script
Consider this code:
All keywords are lowercase
It is “var”, not “Var”, not “VAR”.
It is “if”, not “If”, not “IF”.
All other variables, function names etc must be typed with consistent capitalization
var id = CRM.GetContextInfo(“company”,”comp_companyid”);
var myBlock = CRM.GetBlock(“opportunitylist”);
If we want to pass the context information correctly to Execute method then the variable 'id' has to be correctly referenced.
In Sage CRM parameters may not be case sensitive if passed directly to the database. E.g. Block names.
In the example above it doesn't matter if we pass 'OpportunityList' or 'opportunitylist' as the parameter as the Database is not case sensitive.
Semicolons should be used to terminate statements but if each statement is on a new line then this may be omitted.
//This is a commented out line
Are commented out
Have a look at this example.
In this example, there are Variables that are defined and an object and method are used.
The rules for legal names are much the same in most programming languages.
- Subsequent characters may be letters, digits, underscores, or dollar signs.
- Numbers are not allowed as the first character.
I can use this code in the Custom Content box of the CompanyBoxLong screen.
and this would cause the message to be written on the screen.
The 'var' keyword is used when variables are declared
var intTotal = 1 + 2 + 3;
var a, b, c, e
But this may be omitted in top-level code but it is also needed for local variables declared in Functions.
Have a look at the image below:
If a variable is declared outside of function definition then it is considered a global variable. This means that the value is accessible and modifiable throughout the program.
If a variable is declared inside of a function then that variable is local. This means that it is created and destroyed every time the function is executed; it cannot be accessed by anything outside the function.
- Primitive data type
- Non-primitive (reference) data type
This is our Hello World example again but this time written in an ASP page.
You can see that in our first example the way in which the value was written out into the interface was to use "document.write" but within the ASP page, we use "Response.Write".
ASP pages & Browser scripts both share the same syntax but they use different objects provide by the environment.