Inventory Web Hooks for custom tables  Topic is solved

Discussions relating to the REST API of Jiwa 7.

Inventory Web Hooks for custom tables

Postby SBarnes » Tue Apr 20, 2021 5:35 pm

We have a customer for whom we have written a custom screen called web categories, the table structure of which is below, basically the screen is a maintenance screen with IN_WebCategoriesMain as the header and Business object and IN_WebCategoriesInventory in a Jiwa grid as a collection item which goes back to lines property on the business object.

Then there is custom route on the REST API called Inventory Master Catalogue that can be called either directly or can fire with a double hop off an inventory web hook.

What the customer now wants to have happen is that if an inventory item is added or deleted from IN_WebCategoriesInventory through the screen that an update will fire a web hook to send the data to the external system as an inventory update seeing the web categories are sent as part of the catalogue data.

The only way I can think to do this is via the following:

1. On the Collection Item(IN_WebCategoriesInventory) iSave add an event that can be attached to like a save end.
2. In a business logic plugin attach to this event and have a new custom web hook fire and call a custom route on the api that will again get the catalogue information together and forward it on to the external system.

Could there be a simpler way to do this that I haven't though of as this starting to do my head in?

Code: Select all
CREATE TABLE [dbo].[IN_WebCategoriesMain](
   [RecID] [uniqueidentifier] NOT NULL,
   [Category1] [varchar](255) NOT NULL,
   [Category2] [varchar](255) NOT NULL,
   [Category3] [varchar](255) NOT NULL,
   [Enabled] [bit] NOT NULL,
   [LastUpdated] [datetime] NULL,
   [CatGrp] [varchar](255) NOT NULL,
 CONSTRAINT [PK_IN_WebCategoriesMain] PRIMARY KEY CLUSTERED
(
   [RecID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO

/****** Object:  Table [dbo].[IN_WebCategoriesInventory]    Script Date: 20/04/2021 3:55:07 PM ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[IN_WebCategoriesInventory](
   [RecID] [uniqueidentifier] NOT NULL,
   [IN_WebCategoriesMain_RecID] [uniqueidentifier] NOT NULL,
   [InventoryID] [char](20) NOT NULL,
   [Enabled] [bit] NOT NULL,
   [LastUpdated] [datetime] NOT NULL,
 CONSTRAINT [PK_IN_WebCategoriesInventory] PRIMARY KEY CLUSTERED
(
   [RecID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO

ALTER TABLE [dbo].[IN_WebCategoriesInventory]  WITH CHECK ADD  CONSTRAINT [FK_IN_WebCategoriesInventory_IN_Main] FOREIGN KEY([InventoryID])
REFERENCES [dbo].[IN_Main] ([InventoryID])
ON UPDATE CASCADE
ON DELETE CASCADE
GO

ALTER TABLE [dbo].[IN_WebCategoriesInventory] CHECK CONSTRAINT [FK_IN_WebCategoriesInventory_IN_Main]
GO

ALTER TABLE [dbo].[IN_WebCategoriesInventory]  WITH CHECK ADD  CONSTRAINT [FK_IN_WebCategoriesInventory_IN_WebCategoriesMain] FOREIGN KEY([IN_WebCategoriesMain_RecID])
REFERENCES [dbo].[IN_WebCategoriesMain] ([RecID])
ON UPDATE CASCADE
ON DELETE CASCADE
GO

ALTER TABLE [dbo].[IN_WebCategoriesInventory] CHECK CONSTRAINT [FK_IN_WebCategoriesInventory_IN_WebCategoriesMain]
GO

Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1619
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 175

Re: Inventory Web Hooks for custom tables  Topic is solved

Postby Mike.Sheen » Thu May 06, 2021 12:50 pm

SBarnes wrote:What the customer now wants to have happen is that if an inventory item is added or deleted from IN_WebCategoriesInventory through the screen that an update will fire a web hook to send the data to the external system as an inventory update seeing the web categories are sent as part of the catalogue data.


Why not just leverage our existing webhook for when products are added or deleted? You could add a check in the handler for the SaveEnd event of the Inventory business logic.

So, our standard one looks like this:
Code: Select all
async public void Inventory_SaveEnd(object sender, System.EventArgs e)
{
   JiwaFinancials.Jiwa.JiwaInventory.Inventory inventory = (JiwaFinancials.Jiwa.JiwaInventory.Inventory)sender;
   string body = inventory.DTO_Serialise().ToJson<JiwaFinancials.Jiwa.JiwaServiceModel.Inventory.InventoryItem>();

   Webhook(inventory.Manager, body, (inventory.InsertFlag) ? "inventory.created" : (inventory.DeleteFlag) ? "inventory.deleted" : "inventory.updated");
}


And tack some code at the end after we send our standard webhook - something like this:

Code: Select all
async public void Inventory_SaveEnd(object sender, System.EventArgs e)
{
   JiwaFinancials.Jiwa.JiwaInventory.Inventory inventory = (JiwaFinancials.Jiwa.JiwaInventory.Inventory)sender;
   string body = inventory.DTO_Serialise().ToJson<JiwaFinancials.Jiwa.JiwaServiceModel.Inventory.InventoryItem>();

   Webhook(inventory.Manager, body, (inventory.InsertFlag) ? "inventory.created" : (inventory.DeleteFlag) ? "inventory.deleted" : "inventory.updated");
   
   if (MyMethodToSeeIfThisItemHasWebCategories)
   {
      string body = // your json for the payload here
      Webhook(inventory.Manager, body, (inventory.InsertFlag) ? "inventory.webcategory.created" : (inventory.DeleteFlag) ? "inventory.webcategory.deleted" : "inventory.webcategory.updated");
   }
}
Mike Sheen
Chief Software Engineer
Jiwa Financials

If I do answer your question to your satisfaction, please mark it as the post solving the topic so others with the same issue can readily identify the solution
User avatar
Mike.Sheen
Overflow Error
Overflow Error
 
Posts: 2444
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 756


Return to REST API

Who is online

Users browsing this forum: No registered users and 3 guests