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

Discussions relating to plugin development, and the Jiwa API.

Webhook is needed when the sales order is processed

Postby kranil7701 » Tue Oct 31, 2023 3:31 pm

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.
kranil7701
I'm new here
I'm new here
 
Posts: 8
Joined: Tue Oct 31, 2023 1:03 pm

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

Postby Mike.Sheen » Tue Oct 31, 2023 4:43 pm

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.
Attachments
Plugin Sales Order Processed Webhook.xml
(8.06 KiB) Downloaded 360 times
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: Webhook is needed when the sales order is processed

Postby SBarnes » Tue Oct 31, 2023 6:23 pm

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.
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1619
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 175

Re: Webhook is needed when the sales order is processed

Postby kranil7701 » Tue Oct 31, 2023 6:35 pm

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
kranil7701
I'm new here
I'm new here
 
Posts: 8
Joined: Tue Oct 31, 2023 1:03 pm

Re: Webhook is needed when the sales order is processed

Postby Mike.Sheen » Tue Oct 31, 2023 6:39 pm

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.
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: Webhook is needed when the sales order is processed

Postby kranil7701 » Tue Oct 31, 2023 6:47 pm

Is this possible for you to show me how you setup this plugin ?
kranil7701
I'm new here
I'm new here
 
Posts: 8
Joined: Tue Oct 31, 2023 1:03 pm

Re: Webhook is needed when the sales order is processed

Postby Mike.Sheen » Wed Nov 01, 2023 10:30 am

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.
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 33 guests