Extensibility of data synchronization with POS – Option 1

Data export from POS

You may attach your own data to objects created in POS and synchronized to the ERP system. To do so, override the Synchronization.GetCustomData function in the POS database. The function returns an XML and takes the type of a synchronized object (int) and its identifier (int) as arguments. The function is run separately for each object to be transferred to the ERP system.

Example of an export procedure

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[Synchronization].[GetCustomData]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT'))
DROP FUNCTION [Synchronization].[GetCustomData]
GO
CREATE FUNCTION [Synchronization].[GetCustomData]
(
@syncType int,
@documentId int
)
RETURNS XML
AS
BEGIN
declare @data XML;
set @data = (select [Implementations].[GetSpecificData](@syncType, @documentId)
for xml path('SpecificElements'), root('CustomData'), type)
return @data
END
GO
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[Implementations].[GetSpecificData]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT'))
DROP FUNCTION [Implementations].[GetSpecificData]
GO
CREATE FUNCTION [Implementations].[GetSpecificData]
(
@syncType int,
@documentId int
)
RETURNS XML
AS
BEGIN
declare @specifics XML;
set @specifics = (select
el.OrdinalNumber as [@OrdinalNumber],
el.SpecificCode as [@SpecificCode],
el. SpecificTypeId as [@SpecificTypeId]
from ExtensionSchema.SpecificDataTable el
inner join Documents.TradeDocuments doc on el.DocumentId = doc.Id
where el.DocumentId = @documentId and @syncType = 45
for xml path('row'))
return @specifics
END
GO
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[Synchronization].[GetCustomData]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT')) DROP FUNCTION [Synchronization].[GetCustomData] GO CREATE FUNCTION [Synchronization].[GetCustomData] ( @syncType int, @documentId int ) RETURNS XML AS BEGIN declare @data XML; set @data = (select [Implementations].[GetSpecificData](@syncType, @documentId) for xml path('SpecificElements'), root('CustomData'), type) return @data END GO IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[Implementations].[GetSpecificData]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT')) DROP FUNCTION [Implementations].[GetSpecificData] GO CREATE FUNCTION [Implementations].[GetSpecificData] ( @syncType int, @documentId int ) RETURNS XML AS BEGIN declare @specifics XML; set @specifics = (select el.OrdinalNumber as [@OrdinalNumber], el.SpecificCode as [@SpecificCode], el. SpecificTypeId as [@SpecificTypeId] from ExtensionSchema.SpecificDataTable el inner join Documents.TradeDocuments doc on el.DocumentId = doc.Id where el.DocumentId = @documentId and @syncType = 45 for xml path('row')) return @specifics END GO
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[Synchronization].[GetCustomData]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT'))
DROP FUNCTION [Synchronization].[GetCustomData]
GO

CREATE FUNCTION [Synchronization].[GetCustomData]
(
    @syncType int,
    @documentId int
)
RETURNS XML
AS
BEGIN

    declare @data XML;
    
    set @data = (select [Implementations].[GetSpecificData](@syncType, @documentId)					
                    for xml path('SpecificElements'), root('CustomData'), type)
    return @data

END
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[Implementations].[GetSpecificData]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT'))
DROP FUNCTION [Implementations].[GetSpecificData]
GO

CREATE FUNCTION [Implementations].[GetSpecificData]
(
    @syncType int,
    @documentId int
)
RETURNS XML
AS
BEGIN

    declare @specifics XML;

    
    set @specifics = (select 					
                    el.OrdinalNumber as [@OrdinalNumber],
el.SpecificCode		 as [@SpecificCode],
                    el. SpecificTypeId	 as [@SpecificTypeId]
                    from ExtensionSchema.SpecificDataTable el
                    inner join Documents.TradeDocuments doc on el.DocumentId = doc.Id
                    where el.DocumentId = @documentId and @syncType = 45 
                    for xml path('row'))
    return @specifics

END
GO

Import on the DataService side

Data import is done in C# code. Each processed object has the CustomData property of the XElement type. You need to deserialize the data and process it yourself.

You may get useful information from the static class WebServiceHelper. For each DataService contract method call, you can get information about the POS instance:

  • POS code
  • POS GUID
  • profile code
  • version

Example of import on the DataService side

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
[DataServiceBusinessModule]
public static class Module
{
[MethodInitializer]
public static void Initialize()
{
var customerService = IoC.Container.Resolve<IDataCustomerExtensionPointService>();
customerService.AfterSaveCustomerEvent += CustomerServiceEx_AfterSaveCustomerEvent;
}
private static void CustomerServiceEx_AfterSaveCustomerEvent(object sender, DTOResultEventArgs<Queue.DTO.CustomerDTO, string, int> e)
{
Console.WriteLine("{0}: {1}", e.Argument, e.EntityRow.CustomData.Name);
var xe = e.EntityRow.CustomData; // XElement
}
}
[DataServiceBusinessModule] public static class Module { [MethodInitializer] public static void Initialize() { var customerService = IoC.Container.Resolve<IDataCustomerExtensionPointService>(); customerService.AfterSaveCustomerEvent += CustomerServiceEx_AfterSaveCustomerEvent; } private static void CustomerServiceEx_AfterSaveCustomerEvent(object sender, DTOResultEventArgs<Queue.DTO.CustomerDTO, string, int> e) { Console.WriteLine("{0}: {1}", e.Argument, e.EntityRow.CustomData.Name); var xe = e.EntityRow.CustomData; // XElement } }
[DataServiceBusinessModule]
public static class Module    
{
   [MethodInitializer]
   public static void Initialize()        
   {
      var customerService = IoC.Container.Resolve<IDataCustomerExtensionPointService>();
      customerService.AfterSaveCustomerEvent += CustomerServiceEx_AfterSaveCustomerEvent;
   }
   private static void CustomerServiceEx_AfterSaveCustomerEvent(object sender, DTOResultEventArgs<Queue.DTO.CustomerDTO, string, int> e)         
   {
      Console.WriteLine("{0}: {1}", e.Argument, e.EntityRow.CustomData.Name);
      var xe = e.EntityRow.CustomData; // XElement
   }
}

Czy ten artykuł był pomocny?