Best sales order event for all new orders  Topic is solved

Discussions relating to plugin development, and the Jiwa API.

Best sales order event for all new orders

Postby DannyC » Thu Jun 01, 2023 11:34 am

I need to write a text string to a sales order custom field when a sales order gets created.
The sales order could be created via the GUI, the REST API, file watcher

The value is dependent upon a characteristic of the debtor, in this case the value for Category5.

Obviously (!) I need to write the plugin in the business logic section.
However which event should I use?
salesOrder.Created
salesOrder.CreateEnd
salesOrder.Creating

salesOrder.Created works well for orders raised via the Jiwa GUI. The user clicks save when ready.
Is that event still applicable for imported orders via REST API etc?

For now, I am doing the stuff on SaveStart and testing for
Code: Select all
if (salesOrder.InvoiceNo =="")
but I really don't need or want the SaveStart code to fire on every save - there's no need. But if that's the best way, cool.
Last edited by DannyC on Thu Jun 01, 2023 1:11 pm, edited 1 time in total.
User avatar
DannyC
Senpai
Senpai
 
Posts: 636
Joined: Fri Mar 22, 2013 12:23 pm
Topics Solved: 30

Re: Best sales order event for all new orders

Postby pricerc » Thu Jun 01, 2023 12:26 pm

If you handle the events in a "BusinessLogicPlugin" class and not a "FormPlugin" Class, then it should apply regardless of how the SalesOrder is created.
/Ryan

ERP Consultant,
Advanced ERP Limited, NZ
https://aerp.co.nz
User avatar
pricerc
Senpai
Senpai
 
Posts: 504
Joined: Mon Aug 10, 2009 12:22 pm
Location: Auckland, NZ
Topics Solved: 20

Re: Best sales order event for all new orders  Topic is solved

Postby Mike.Sheen » Thu Jun 01, 2023 12:58 pm

All our business logic for maintenance type forms (which sales orders is) has a CreateEnd event raised when a new order is created.

That didn't entirely suit our needs for sales orders, as we also wanted to know when an order was created if it was from a quote or job cost invoice or whatever - so we added another event, Created which includes parameters indicating what type of new sales order this is (e_NewSalesOrder (0), e_NewSalesOrderCreditNote(1), e_NewSalesOrderJobCost(2) or e_NewSalesOrderQuote(3)) and also a nullable quote object which is not null if the order was created from a quote.

So, when a sales order is created, the business logic raises two events:

CreateEnd(sender As Object, e As System.EventArgs)
and then
Created(sender As Object, e As System.EventArgs, ByVal NewSalesOrderType As NewSalesOrderTypes, ByRef SourceQuoteObject As JiwaSales.SalesQuote.SalesQuote)

Both events get fired regardless of of where it was created - form, REST API - even a a custom 3rd party application.

In either event you can set your custom field contents there and everything will work as you expect.

However, you mention you are setting the sales order custom field based on the value of a debtor category 5 - so you'll also want to listen to the Salesorder.Debtor.Read event as if the user changes the debtor after creating the order, you'll need to know about that.

Your test in SaveStart for InvoiceNo =="" might work, but it won't always. If in the SaveStart event you want to know if the order is being saved for the first time, check the InsertFlag property instead. That will be True if the order being saved is a new order. You cannot rely on InvoiceNo =="" as a system configuration can be set to allow the user to key an invoice no in for a new order, so that test won't work in that scenario.
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: Best sales order event for all new orders

Postby DannyC » Thu Jun 01, 2023 1:10 pm

Understood.
Thx
User avatar
DannyC
Senpai
Senpai
 
Posts: 636
Joined: Fri Mar 22, 2013 12:23 pm
Topics Solved: 30

Re: Best sales order event for all new orders

Postby SBarnes » Thu Jun 01, 2023 6:02 pm

Is that event still applicable for imported orders via REST API etc?


On the whole events in the business logic do not discriminate about the process they are running in, if you ever only want the event to run in the user interface then use a form plugin and attach the events there.

If you ever need to check if the business object is attached to a form there is a client property it will be null when there is no form.
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1619
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 175


Return to Technical and or Programming

Who is online

Users browsing this forum: No registered users and 17 guests