SYNC ENHANCEMENTS 16 Jan 15 – bsp hooks – cases 0000068058 and 0000097128 We now have the ability to affect and interrupt after update, insert and before deletion of records when syncing as well as returning a product price. You can create a bfn function in the winman master database called [bfn_GetSyncProductPrice] which will return a product price and update the product in its relevant system. This will superceed the existing function [bfn_GetSyncPrice]. Example: USE [WinManMaster] GO /****** Object: UserDefinedFunction [dbo].[bfn_GetSyncProductPrice] 16/01/2015 11:02:31 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO Script Date: --Nash15Jan15 - Created - case 0000097128 - example ALTER FUNCTION [dbo].[bfn_GetSyncProductPrice] ( @SourceDatabase nvarchar(100), @DestinationDatabase nvarchar(100), @Product bigint ) RETURNS Decimal(17,5) AS BEGIN DECLARE @Price AS Decimal(17,5) SELECT @Price = CASE WHEN LOWER(@SourceDatabase) = 'release94' THEN 63.25698 WHEN LOWER(@DestinationDatabase) = 'chargepointus' THEN 4.67 ELSE 3.2 END RETURN @Price END You can now create a bespoke procedure [bsp_SyncAfterWriteRecord] after update and insertion of any record as well as before deletion. Create the procedure and execute it in the system you are wanting to affect. Example: USE [WinMan] GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO --Nash15Jan15 - Created - case 0000068058 example ALTER PROCEDURE [dbo].[bsp_SyncAfterWriteRecord] ( @TableName nvarchar(100), @Identifier @Type @DeleteGUID bigint = 0, nvarchar(50), nvarchar(100) = '' ) AS SET NOCOUNT OFF; DECLARE @Date as datetime SET @Date = getdate() --@Type = 'Insert' or 'Update' or 'BeforeDelete' --@DeleteGUID gets passed when deleting, use this to identify the record, @Identifier is set when Updating and Inserting --tested against release94 --chargepointus - insert scr after product insert IF ((LOWER(@TableName) = 'products') AND (LOWER(@Type) = 'Insert')) BEGIN INSERT INTO [dbo].[SupplierCrossReferences] ([Product] ,[Supplier] ,[SupplierDescription] ,[SupplierProductNumber] ,[NormalCost] ,[DateLastQuoted] ,[Discount] ,[OriginalContractQuantity] ,[ContractQuantityOutstanding] ,[ContractDate] ,[MinimumStock] ,[MaximumStock] ,[LeadTime] ,[UnitOfMeasureFactor] ,[KanbanDeliveryDays] ,[CreatedUser] ,[CreatedDate] ,[LastModifiedUser] ,[LastModifiedDate] ,[Type] ,[Comments] ,[BatchQuantity] ,[Location] ,[SupplierSequence] ,[MinimumOrderQuantity] ,[OptimumOrderQuantity] ,[ProductShelfLife] ,[TrackShelfLife] ,[ShelfLife] ,[ShelfLifeGuarantee] ,[ShelfLifeOrigin] ,[ExpirationMethod] ) VALUES ( @Identifier, 953,--ABF FREIGHT SYSTEM INC 'ABF FREIGHT SYSTEM INC CROSS REF', 111112, 105.98, @Date, NULL, 1, 1, @Date, 1, 1, 1, NULL, 'YYYYYNN', 'TTW', @Date, 'TTW', @Date, 'P', '', 0, NULL, 99, NULL, NULL, 1, 0, NULL, NULL, NULL, NULL ) END --chargepointus - update scr after product update IF ((LOWER(@TableName) = 'products') AND (LOWER(@Type) = 'update')) BEGIN UPDATE [dbo].[SupplierCrossReferences] SET [NormalCost] = 94.21 ,[LastModifiedUser] = 'TTW' ,[LastModifiedDate] = @Date WHERE Product = @Identifier AND Supplier = 953 END --chargepointus - delete scr before product deletion IF ((LOWER(@TableName) = 'products') AND (LOWER(@Type) = 'beforedelete')) BEGIN DECLARE @Product bigint SELECT @Product = Product FROM Products WHERE SyncGUID = @DeleteGUID DELETE FROM [dbo].[SupplierCrossReferences] WHERE Product = @Product AND Supplier = 953 END