Tutorial - Logistics - Validators (TaxId)

DocDigitizer WorldObjects Tutorial - create validator for tax identifier

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

Add Validation to ShippingGuide

Open your Visual Code and login.
Open object ShippingGuide.

Add the following property that will identify the Country that vendor is associated:

Reference vendorCountry to Global.Country

Add to the existing property "vendorTaxId" the following validation rule:

  • Validate Tax Id by country

Find property vendorTaxId and bellow the property and the following code lines

Validation
	const country = _arguments && _arguments.length !== 0 ? _arguments[0] : _this.vendorCountry;
	return _validate.CountryTIN(country, _value);
End Validation
  • _value reference the property in the scope.
  • _this reference object in the scope.
  • _arguments array of arguments that can be passes do the Validation function

The Validation will use the country value passed in the arguments [arguments[0]) or if null, the value of the property vendorCountry

The result of the validation will be structured:

  • IsValid Boolean
  • ErrorMessage error validation message if IsValid is False

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

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 Validaters

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

static void ValidateShippingGuide()
 {
   guide1.vendorCountry = Country.References.PT;
   Console.WriteLine("");
   Console.WriteLine($"TaxId Validation for {guide1.vendorTaxId} @ {guide1.vendorCountry.Name} = " + $"{guide1.vendorTaxId_Validate()}");
   guide1.vendorTaxId = "999999998";
   Console.WriteLine($"TaxId Validation for {guide1.vendorTaxId} @ {guide1.vendorCountry.Name} = " + $"{guide1.vendorTaxId_Validate()}");
   guide1.vendorTaxId = "123456789";
   Console.WriteLine($"TaxId Validation for {guide1.vendorTaxId} @ {guide1.vendorCountry.Name} = " + $"{guide1.vendorTaxId_Validate()}");
   Console.WriteLine($"TaxId Validation for {guide1.vendorTaxId} @ {Country.References.US.Name} = " + $"{guide1.vendorTaxId_Validate(Country.References.US)}");
 }

Example you are setting different values for the vendor tax id (property: vendorTaxId), using the country of the vendor or passing this value as argument and calling Validation function and printing the results.

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

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

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

882

The solution is available:
Source