Page 1 of 1

Webhook is needed when the sales order is processed

PostPosted: Tue Oct 31, 2023 3:31 pm
by kranil7701
Hi , I am looking a webhook event that will trigger when we process the sales order .
Option to process : https://prnt.sc/nK2XHay9EL5z
So Basically we have webhook events like saleorder.created or saleorder.updated that always work when we click the save button inside the sales order .
But we’d like to trigger the webhook as soon as an invoice is processed. https://prnt.sc/nK2XHay9EL5z

Please see video below to check how I am doing it right now. So I have to save again even after processing the invoice to make the webhook trigger .
https://www.loom.com/share/e1a48a340777 ... 36cb384e29

SO please let me know about any webhook that will trigger exactly as soon as we press "Process" button .
Or any alternate way to do so.
Thanks and regards.

Re: Webhook is needed when the sales order is processed  Topic is solved

PostPosted: Tue Oct 31, 2023 4:43 pm
by Mike.Sheen
We don't seem to be raising a sales order saveend event when a sales order is processed, which is why the webhook is not firing. We have other events in the business logic to respond to a process event - but out of the box not a webhook.

Ideally you probably want to create a new event - salesorder.processed so you can subscribe to that and know that only when a sales order is processed is that subscription going to be pushed.

You do that by adding to the WebHookEvents collection of the REST API:

Code: Select all
JiwaFinancials.Jiwa.JiwaServiceModel.RESTAPIPlugin.WebHookEvents.Add(new JiwaFinancials.Jiwa.JiwaServiceModel.WebHookEvent { Name = "salesorder.processed", Description = "Occurs when a sales order is processed" });


And then you want to handle the Processed event of the sales order business logic and in there trigger the webhook:

Code: Select all
public void Setup(JiwaFinancials.Jiwa.JiwaApplication.IJiwaBusinessLogic JiwaBusinessLogic, JiwaFinancials.Jiwa.JiwaApplication.Plugin.Plugin Plugin)
{
   JiwaFinancials.Jiwa.JiwaSales.SalesOrder.SalesOrder salesOrder = (JiwaFinancials.Jiwa.JiwaSales.SalesOrder.SalesOrder)JiwaBusinessLogic;
   salesOrder.Processed += SalesOrder_Processed;
}

private void SalesOrder_Processed(object sender, System.EventArgs e)
{
   JiwaFinancials.Jiwa.JiwaSales.SalesOrder.SalesOrder salesOrder = (JiwaFinancials.Jiwa.JiwaSales.SalesOrder.SalesOrder)sender;
   string body = salesOrder.DTO_Serialise().ToJson<JiwaFinancials.Jiwa.JiwaServiceModel.SalesOrders.SalesOrder>();
   
   JiwaFinancials.Jiwa.RESTAPIPlugin.BusinessLogicPlugin.Webhook(salesOrder.Manager, body, "salesorder.processed", "REST API");
}


Attached is a plugin which does this - tested with Jiwa 7.2.1. SR 17 and the REST API plugin version 7.2.1.52.

Note that you'll need to create a subscription which subscribes to the salesorder.processed event, and not the salesorder.updated event like you currently are. You can also subscribe to both if you like.

Re: Webhook is needed when the sales order is processed

PostPosted: Tue Oct 31, 2023 6:23 pm
by SBarnes
Having actually implemented a custom web hook for order processing previously one thing you may need to consider if you are also looking for debtor updates as well you may not get one even though the debtors balance has changed.

The reason I mention it if this is for a web store balances will change on the debtor with processing of any order which could effect hitting the credit limit or not.

Re: Webhook is needed when the sales order is processed

PostPosted: Tue Oct 31, 2023 6:35 pm
by kranil7701
Thanks for the help so far.
I have tried to setup the webhook using the Rest api .
https://prnt.sc/rWjfgzJzaLKO
You can see in the above screenshot that its even setup correctly as I am above to retrieve them in the subscriptions https://prnt.sc/-rt5azEXKN7E
But still the webhook is firing at save button only and not on the process.
Please help to fix this.
Thanks

Re: Webhook is needed when the sales order is processed

PostPosted: Tue Oct 31, 2023 6:39 pm
by Mike.Sheen
The plugin I provided works for me with the Jiwa version and the REST API Plugin version I cited.

If yours is not working, then first verify you are on the same versions.

Also try on a clean demo database - I have no way of knowing what other plugins you have which may be changing behaviours.

Re: Webhook is needed when the sales order is processed

PostPosted: Tue Oct 31, 2023 6:47 pm
by kranil7701
Is this possible for you to show me how you setup this plugin ?

Re: Webhook is needed when the sales order is processed

PostPosted: Wed Nov 01, 2023 10:30 am
by Mike.Sheen
kranil7701 wrote:Is this possible for you to show me how you setup this plugin ?


If you want one on one personal support, please engage our helpdesk.