Difference between revisions of "Understanding Macros"

From Lianjapedia
Jump to: navigation, search
Line 3: Line 3:
 
Lianja makes extensive use of { expression } macros which are substituted dynamically.
 
Lianja makes extensive use of { expression } macros which are substituted dynamically.
  
These can be specified in many of the attributes when building Apps.
+
These can be specified in many of the UI attributes when building Apps.
  
 
* Section headers
 
* Section headers
Line 14: Line 14:
 
* Data binding controlsources  
 
* Data binding controlsources  
 
* + many more
 
* + many more
 +
 +
The use of {expression}  is very effective in NoCode App development.
 +
 +
In their simplest use just put { expression } anywhere you want a dynamic value to be substituted.
 +
 +
<pre>{customers.customerid}</pre>
 +
 +
===Understanding macro substitution in the Lianja Web/Mobile Client===
 +
 +
Just as you can use {expression} macros in the Lianja Desktop Client you can also use these in your Web and Mobile Apps.
 +
 +
<code lang="javascript">
 +
Lianja.evaluate("calculateCustomerBalance('{customers.name}’)",
 +
    function(result)
 +
    {
 +
        Lianja.getElementByID("mypage.mysection.myfield").text = result;
 +
    },
 +
    function(errormessage)
 +
    {
 +
        Lianja.showErrorMessage("Failed to calculate customer balance");
 +
    }
 +
);
 +
// execution continues before the result is returned
 +
</code>
 +
 +
Macros are evaluated from left to right:
 +
 +
<code lang="javascript">
 +
Lianja.evaluate("calculateCustomerBalance('{customers.name}','{customers.id}’)",
 +
    function(result)
 +
    {
 +
        Lianja.getElementByID("mypage.mysection.myfield").text = result;
 +
    },
 +
    function(errormessage)
 +
    {
 +
        Lianja.showErrorMessage("Failed to calculate customer balance");
 +
    }
 +
);
 +
// execution continues before the result is returned
 +
</code>
 +
 +
Macros can be nested so that the inner macros are evaluated before the outer macros. This provides the ability to query information from the server and have that information substituted into another call to the server.
 +
 +
<code lang="javascript">
 +
Lianja.evaluate("calculateCustomerBalance('{customers.name}'," + "{getCustomerID('{{customers.custid}}')}")),
 +
    function(result)
 +
    {
 +
        Lianja.getElementByID("mypage.mysection.myfield").text = result;
 +
    },
 +
    function(errormessage)
 +
    {
 +
        Lianja.showErrorMessage("Failed to calculate customer balance");
 +
    }
 +
);
 +
// execution continues before the result is returned
 +
</code>
 +
 +
This will result in the following macro substitutions being performed in this order.
 +
 +
<nowiki> {{customers.custid}} lets call this result3
 +
{customers.name} let's call this result1
 +
{getCustomerID("result3")} let's call this result2</nowiki>
 +
  Lianja.evaluate("calculateCustomerBalance('result1', "result2")
 +
 +
Bear in mind that just as in the Lianja Desktop Client we can specify validation expressions that use {...} macros and also use {} to be substituted for the current value of the UI control being validated.

Revision as of 08:45, 7 December 2017

Under construction

Lianja makes extensive use of { expression } macros which are substituted dynamically.

These can be specified in many of the UI attributes when building Apps.

  • Section headers
  • Section footers
  • As part of the URL to any WebViews or sidebar gadgets
  • In Validation expressions
  • In validation error messages
  • In filter expressions
  • In SQL statements
  • Data binding controlsources
  • + many more

The use of {expression} is very effective in NoCode App development.

In their simplest use just put { expression } anywhere you want a dynamic value to be substituted.

{customers.customerid}

Understanding macro substitution in the Lianja Web/Mobile Client

Just as you can use {expression} macros in the Lianja Desktop Client you can also use these in your Web and Mobile Apps.

Lianja.evaluate("calculateCustomerBalance('{customers.name}’)",
    function(result)
    {
        Lianja.getElementByID("mypage.mysection.myfield").text = result;
    },
    function(errormessage)
    {
        Lianja.showErrorMessage("Failed to calculate customer balance");
    }
);
// execution continues before the result is returned

Macros are evaluated from left to right:

Lianja.evaluate("calculateCustomerBalance('{customers.name}','{customers.id}’)",
    function(result)
    {
        Lianja.getElementByID("mypage.mysection.myfield").text = result;
    },
    function(errormessage)
    {
        Lianja.showErrorMessage("Failed to calculate customer balance");
    }
);
// execution continues before the result is returned

Macros can be nested so that the inner macros are evaluated before the outer macros. This provides the ability to query information from the server and have that information substituted into another call to the server.

Lianja.evaluate("calculateCustomerBalance('{customers.name}'," + "{getCustomerID('{{customers.custid}}')}")),
    function(result)
    {
        Lianja.getElementByID("mypage.mysection.myfield").text = result;
    },
    function(errormessage)
    {
        Lianja.showErrorMessage("Failed to calculate customer balance");
    }
);
// execution continues before the result is returned

This will result in the following macro substitutions being performed in this order.

 {{customers.custid}} lets call this result3
 {customers.name} let's call this result1
 {getCustomerID("result3")} let's call this result2
 Lianja.evaluate("calculateCustomerBalance('result1', "result2")

Bear in mind that just as in the Lianja Desktop Client we can specify validation expressions that use {...} macros and also use {} to be substituted for the current value of the UI control being validated.