StockLevelChanged event running more than once  Topic is solved

Discussions relating to plugin development, and the Jiwa API.

StockLevelChanged event running more than once

Postby sameermoin » Fri Dec 30, 2022 4:28 pm

Hi Everyone,

I am using the StockLevelChanged event on ApplicationManagerPlugin class. The problem is when I activate a Stock Take from Inventory > Stock Take and put the debugger in the code, the debugger hit multiple times for a single inventory.

I checked the REST API plugin, and their inventory.stocklevel webhook was implemented using the same event and because of this behavior the webhook also triggered multiple time

Is this normal behavior? If so how can I make it run only one time for each inventory? It exhausts the other application endpoint.
sameermoin
Regular Contributor
Regular Contributor
 
Posts: 75
Joined: Wed Jun 15, 2022 4:02 am
Topics Solved: 1

Re: StockLevelChanged event running more than once

Postby SBarnes » Fri Dec 30, 2022 4:48 pm

Whilst I am not sure about it running twice for this particular hook my experience with this hook is that you usually end up inundating an external system with events to do with SOH.

What I found as a better system was to put in place a set of SQL triggers that would update a table with the SOH value and a date and time, then what simply became the easiest solution was to then use a scheduled plugin to run at an interval of something like five minutes and send the data that way and then simply keep the last time the schedule ran in a system setting.

It also meant I was able to avoid two issues which were

  • Sending details for products that did not have their web enabled flag set or weren't related to the relevant warehouse
  • Things getting out of order in terms of hook events and you ending up with the wrong SOH value

That being said try lengthening the retry interval you might be experiencing the behavior of hooks being sent multiple times and lengthening the hook interval usually fixes this.
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1619
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 175

Re: StockLevelChanged event running more than once

Postby sameermoin » Fri Dec 30, 2022 4:58 pm

SBarnes wrote:
  • Sending details for products that did not have their web enabled flag set or weren't related to the relevant warehouse
  • Things getting out of order in terms of hook events and you ending up with the wrong SOH value



I am filtering inventory based on the warehouse and then querying for stocks. the only problem I am facing is that it's running more than once
sameermoin
Regular Contributor
Regular Contributor
 
Posts: 75
Joined: Wed Jun 15, 2022 4:02 am
Topics Solved: 1

Re: StockLevelChanged event running more than once

Postby SBarnes » Fri Dec 30, 2022 5:01 pm

Then see if lengthening the retry interval solves the issue.
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1619
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 175

Re: StockLevelChanged event running more than once

Postby Mike.Sheen » Tue Jan 03, 2023 11:04 am

sameermoin wrote:when I activate a Stock Take from Inventory > Stock Take and put the debugger in the code, the debugger hit multiple times for a single inventory.


I'll test that scenario and if I can repro it, I will see what work-arounds are possible.

It may be by design - depending on how the stock take is adjusting the stock level - for example, if the stock take is reducing the stock level of an item it may fire the webhook event for each line detail - not just the item itself.
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

Re: StockLevelChanged event running more than once  Topic is solved

Postby Mike.Sheen » Tue Jan 03, 2023 11:36 am

Mike.Sheen wrote:It may be by design - depending on how the stock take is adjusting the stock level - for example, if the stock take is reducing the stock level of an item it may fire the webhook event for each line detail - not just the item itself.


This is exactly what it is. The StockLevelChanged webhook is invoked whenever the WarehouseSOHUpdateEvent is raised by the JiwaApplication.Manager. The stock take will cause that event to be raised for each line detail when saving a stock take that is being activated.

If you are not familiar with Jiwa's Line Detail concept - to give you a brief explanation it means stock levels are comprised of multiple line details which represent a discrete inwards movement of the stock. If you have 10 left of an item in stock in a warehouse, there may be anywhere between 1 and 10 line details representing that quantity - each with potentially different costs, bin locations, expiry dates and serial numbers.

If you need to only have one stock level changed event, then you will need to create an intermediate receiver for the webhook which aggregates and then transmits a single webhook.
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

Re: StockLevelChanged event running more than once

Postby sameermoin » Tue Jan 03, 2023 6:35 pm

Mike.Sheen wrote:If you need to only have one stock level changed event, then you will need to create an intermediate receiver for the webhook which aggregates and then transmits a single webhook.


Hi Mike, thanks for your response.

I didn't get this. I am interested in only the last updated quantity but the problem is how do I know that the event for x Inventory is the last updated?

for example, let's say 1001 inventory and it's updating four times due to multiple lines so its stocklevel event will also run four times, but how do I know from this event that this is the last run?
sameermoin
Regular Contributor
Regular Contributor
 
Posts: 75
Joined: Wed Jun 15, 2022 4:02 am
Topics Solved: 1

Re: StockLevelChanged event running more than once

Postby Mike.Sheen » Fri Feb 10, 2023 1:51 pm

sameermoin wrote:I am interested in only the last updated quantity but the problem is how do I know that the event for x Inventory is the last updated?

for example, let's say 1001 inventory and it's updating four times due to multiple lines so its stocklevel event will also run four times, but how do I know from this event that this is the last run?


Because the most recent one is the last one?

If you have multiple events signaling a change to the stock level, then the most recent one is the one you are interested in.
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 Technical and or Programming

Who is online

Users browsing this forum: No registered users and 28 guests