Tutorial - Logistics - Formatters

DocDigitizer WorldObjects Tutorial - create formatters

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

Add Format to TransportGuide

Open your Visual Code and login.
Open object TransportGuide.

Add to the existing property "deliverDate" the formatter rule that format the date in accordance with Culture/Language format or custom format.

Find property "deliverDate" and above the property and the following code lines

Property deliverDate    type Date    description "Deliver Date"
	Format 
		if (!_value) return null;

		const format = !_arguments || _arguments.length === 0 ? 'yyyy-MM-dd' : _arguments[0];
		const culture = _arguments && _arguments.length > 1 ? _arguments[1].Code : null;
            
		return _utilities.FormatDateTime(_value, format, culture);
	End Format
  • _value reference the property in the scope.
  • _arguments reference the arguments pass the formatter function.
    The formatter accept the following arguments:
  • format custom date format
  • culture code of Culture (Country/Language) to reference date format associated with (see object "LanguageDialect" and "Country" in the "Global" workspace)

The full code of the TransportGuide have to be:

Object TransportGuide
Version 1.0.0

Property documentNumber type Text    description "Document Number"
	Validation 
		return !_value ? "Value must be filled" : null;
	End Validation
Property transporterName    type Text    description "Transporter Name"
Property destinationAddress    type Text    description "Destination Address"
Reference destinationCountry    to Global.Country   
Property deliverDate    type Date    description "Deliver Date"
	Format 
		if (!_value) return null;

		const format = !_arguments || _arguments.length === 0 ? 'yyyy-MM-dd' : _arguments[0];
		const culture = _arguments && _arguments.length > 1 ? _arguments[1].Code : null;
            
		return _utilities.FormatDateTime(_value, format, culture);
	End Format

Collection shippingGuides of ShippingGuide objects

Primary Indexer documentNumber //Property documentNumber must have unique values

Validation
	return _this.shippingGuides.length > 0 ? null : "Must have at least one shipping guide";
End Validation

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 FormatTransportGuide()
{
  string dateFormat = "dd-MM-yyy";
  Console.WriteLine("");
  Console.WriteLine($"  {dateFormat}: {transport.deliverDate_Format(dateFormat)}");

  dateFormat = @"dddd, dd MMMM yyyy";
  Console.WriteLine("");
  Console.WriteLine($"  {dateFormat}: {transport.deliverDate_Format(dateFormat)}");
  Console.WriteLine("");
  Console.WriteLine($"  {dateFormat} @ {Country.References.PT.PrimaryLanguage.ISO2}: " + $"{transport.deliverDate_Format(dateFormat, Country.References.PT.PrimaryLanguage)}");
  Console.WriteLine($"  {dateFormat} @ {LanguageDialect.References.en_US.Code}: " + $"{transport.deliverDate_Format(dateFormat, LanguageDialect.References.en_US)}");
}

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

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

Run the program and in the command prompt you should see the messages of the different date format in accordance with arguments:

  • format
  • culture(country/language)
491

The solution is available:
Source