Sales order Web hook double up  Topic is solved

Discussions relating to the REST API of Jiwa 7.

Sales order Web hook double up

Postby SBarnes » Wed Mar 02, 2022 2:44 pm

We have a customer that is getting double up on web hooks for sales order namely you get a create and update when an order is created.

I believe the issue is arising because there is a customisation that asks the user on the creation of the order if they want to automatically print the picking slip.

The only way I can think of to short circuit this would be to set a flag in the generic object list on the print event of the sales order or in the customisation code and then short circuit the event firing that sends the hook and remove the flag and bail out before sending the hook.

Is there an easier way to overcome this?
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1619
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 175

Re: Sales order Web hook double up

Postby Mike.Sheen » Wed Mar 02, 2022 2:58 pm

SBarnes wrote:We have a customer that is getting double up on web hooks for sales order namely you get a create and update when an order is created.

I believe the issue is arising because there is a customisation that asks the user on the creation of the order if they want to automatically print the picking slip.

The only way I can think of to short circuit this would be to set a flag in the generic object list on the print event of the sales order or in the customisation code and then short circuit the event firing that sends the hook and remove the flag and bail out before sending the hook.

Is there an easier way to overcome this?


Webhooks are sent on the occurrence of the SaveEnd event of a business logic object - so in your case it sounds like your sales order is being saved twice - which actually is needed, because the for the Crystal report to print it needs to have the data saved in the table - that's the first save - and when you print anything it adds a print log entry for the sales order and saves the sales order, which is how the print log entry is saved - so that's the second save.

Technically, the webhook is being sent twice and rightly so - it should be sent each time the subscribed resource (sales orders in this case) changes.

If you do as you propose and prevent the sending of the second webhook which occurs when the print log is updated - then you'll lose getting webhooks when the user loads an existing order and prints something which triggers a save - which may not be important to you but is worth considering. Be aware also that throwing client cancelled exceptions or similar within the business logic will result in the client (Jiwa application) not responding properly - it won't receive the necessary event to trigger a re-read after save.

If you can devise a solution which works, then great - but if not we'll need a sample plugin which exhibits the issue - then we can work through finding a suitable solution.
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: Sales order Web hook double up  Topic is solved

Postby SBarnes » Wed Mar 02, 2022 3:06 pm

Hi Mike,

Thanks for the reply the use of the flag I was actually looking at for changing in the REST API or a custom web hook like salesorder.updatedignoreprint that would do it and then not use salesorder.updated at all.

Code: Select all
async public void SalesOrder_SaveEnd(object sender, System.EventArgs e)
    {

        //If flag set in generic object list remove flag and return
        JiwaFinancials.Jiwa.JiwaSales.SalesOrder.SalesOrder salesOrder = (JiwaFinancials.Jiwa.JiwaSales.SalesOrder.SalesOrder)sender;
        string body = salesOrder.DTO_Serialise().ToJson<JiwaFinancials.Jiwa.JiwaServiceModel.SalesOrders.SalesOrder>();

        Webhook(salesOrder.Manager, body, (salesOrder.InsertFlag) ? "salesorder.created" : "salesorder.updated");
    }
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1619
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 175


Return to REST API

Who is online

Users browsing this forum: No registered users and 3 guests