Best way of aborting adding items to sales order?  Topic is solved

Discussions relating to plugin development, and the Jiwa API.

Best way of aborting adding items to sales order?

Postby DannyC » Mon Sep 17, 2018 8:05 pm

When adding items to sales order lines, using the search window we dbl-click several items which puts the item in the lower panel, then click the green "select & close".
Jiwa then goes & adds the item(s) to the sales order.

I am using the event
Code: Select all
SalesOrder.SalesOrderLines.Adding
to check some conditions for each item as maybe there are business rules which preclude adding an item. At the moment when an item meets the condition(s), I am using
Code: Select all
throw new JiwaFinancials.Jiwa.JiwaApplication.Exceptions.ClientCancelledException
but this completely aborts adding all other items to the sales order.

What I'd like to do (after displaying a warning to the user) is to skip over adding that item & continue to add the other items.
If I use SalesOrderLines.Remove(item) it displays an error because (I assume) the item hasn't been added yet to the lines collection.
I wonder is there a better way to do it?

Maybe within the Search window I can do the check so the item never even gets to be added? Although I don't favour that as they can avoid by just typing directly into the SO line.
Last edited by DannyC on Tue Sep 18, 2018 9:59 am, edited 1 time in total.
User avatar
DannyC
Senpai
Senpai
 
Posts: 638
Joined: Fri Mar 22, 2013 12:23 pm
Topics Solved: 30

Re: Best way of aborting adding items to sales order?

Postby Scott.Pearce » Tue Sep 18, 2018 9:27 am

Version?
Scott Pearce
Senior Analyst/Programmer
Jiwa Financials
User avatar
Scott.Pearce
Senpai
Senpai
 
Posts: 743
Joined: Tue Feb 12, 2008 11:27 am
Location: New South Wales, Australia
Topics Solved: 221

Re: Best way of aborting adding items to sales order?

Postby DannyC » Tue Sep 18, 2018 9:58 am

7.2.
C#
User avatar
DannyC
Senpai
Senpai
 
Posts: 638
Joined: Fri Mar 22, 2013 12:23 pm
Topics Solved: 30

Re: Best way of aborting adding items to sales order?  Topic is solved

Postby Scott.Pearce » Tue Sep 18, 2018 10:06 am

In 7.2 the Adding() event has a parameter of type System.ComponentModel.CancelEventArgs passed in by reference. This parameter is generally named e. So, in your adding handler, set it's Cancel property to true. This was put in place in v7.2 to handle the exact situation you are in.
Scott Pearce
Senior Analyst/Programmer
Jiwa Financials
User avatar
Scott.Pearce
Senpai
Senpai
 
Posts: 743
Joined: Tue Feb 12, 2008 11:27 am
Location: New South Wales, Australia
Topics Solved: 221

Re: Best way of aborting adding items to sales order?

Postby DannyC » Tue Sep 18, 2018 10:31 am

Wooo hooo! Thanks Scott, perfect.
User avatar
DannyC
Senpai
Senpai
 
Posts: 638
Joined: Fri Mar 22, 2013 12:23 pm
Topics Solved: 30


Return to Technical and or Programming

Who is online

Users browsing this forum: No registered users and 14 guests

cron