Tutorial - Logistics - Expressions

DocDigitizer WorldObjects Tutorial - create formatters

We will continuing using previous tutorial "Logistics" and add formatter to show how to use this feature

Add Expression to ShippingGuide

Open your Visual Code and login.
Open object ShippingGuide.

To demonstrate the capabilities of the Expressions, we will add 2 new properties ( first & last client name) that will retrieve is values from another property (full client name).
Add the
Add the following properties and expressions:

Property clientFirstName 
    Expression 
        var names = !_this.clientName ? [] : _this.clientName.split(/\b\s+/);
        return names.length > 0 ? names[0] : null; 
    End Expression

Property clientLastName
    Expression 
        const names = !_this.clientName ? [] : _this.clientName.split(/\b\s+/);
        return names.length > 0 ? names[names.length - 1] : null; 
    End Expression
  • _this reference object in the scope.

The full code of the ShippingGuide have to be:

Object ShippingGuide
Version 1.0.0

Property clientName            type Text    description "Client Name"
Property clientTaxId              type Text    description "Client Tax ID"
Property documentNumber type Text    description "Document Number"
Property emissionDate         type Date    description "Emission Date"
Property totalAmount           type Decimal    description "Total Amount"
Property vatAmount             type Decimal    description "Vat Amount"
Property vendorName          type Text    description "Vendor Name"
Property vendorTaxId           type Text    description "Vendor Tax ID"
    Validation
        const country = _arguments && _arguments.length !== 0 ? _arguments[0] : _this.vendorCountry;
        return _validate.CountryTIN(country, _value);
    End Validation

Property clientFirstName 
    Expression 
        var names = !_this.clientName ? [] : _this.clientName.split(/\b\s+/);

        return names.length > 0 ? names[0] : null; 
    End Expression

Property clientLastName
    Expression 
        const names = !_this.clientName ? [] : _this.clientName.split(/\b\s+/);

        return names.length > 0 ? names[names.length - 1] : null; 
    End Expression

Primary Indexer documentNumber //Property documentNumber must have unique values

Collection items of ShippingItem objects //list (collection) of objects of type "ShippingItem"

Reference currency to MyObjects.Currency 

Reference vendorCountry to Global.Country

Download & Update Nuget packages

Build and download Nuget packages.
On build file ("Logistics") select "Download" (choosing directory where you want to download the files)

Open your Visual Studio and the project previous created "Tutorial - Logistics".

Update the 2 Nuget packages on your Visual Studio project.
note: before updating, on command prompt (cmd), PowerShell or Package Manager Console of Visual Studio execute the command bellow

dotnet nuget locals all --clear

This clean nuget cache of the system, ensuring that version want is running

Use of Formatters

On class "Program.cs" add the following function:

static void ExpressionShippingGuide()
{
  guide1.clientName = "First Middle Last";
  Console.WriteLine("");
  Console.WriteLine("Client Name :          " + guide1.clientName);
  Console.WriteLine("Client First Name:     " + guide1.clientFirstName);
  Console.WriteLine("Client Last Name:      " + guide1.clientLastName);
}

Add call on "main" to the function that you have create.

static void Main(string[] args)
{
  //ShowCatalogCurrency();
  //ShowCatalogCountry();
  CreateTransportGuide();
  //ValidateTransportGuide();
  //ValidateShippingGuide();
  //FormatTransportGuide();
  ExpressionShippingGuide();
}

Run the program and in the command prompt you should see the messages of the expressions performed.

391391

The solution is available:
Source


Did this page help you?