Deleting a stock take line  Topic is solved

Discussions relating to Jiwa 7 plugin development, and the Jiwa 7 API.

Deleting a stock take line

Postby Riyaz » Thu Aug 14, 2025 1:09 am

Hi There

We are trying to create a plugin to delete a stock take line, so far enabled the bin button and it also deletes the line, but come up with object reference error on saving. Kindly advise, plugin is also attached.
Attachments
Plugin Stock Take- Add Delete button .xml
(34.61 KiB) Downloaded 512 times
Riyaz
Kohai
Kohai
 
Posts: 254
Joined: Wed Dec 02, 2015 2:05 pm
Topics Solved: 2

Re: Deleting a stock take line  Topic is solved

Postby Mike.Sheen » Thu Aug 14, 2025 1:14 pm

This is the code which is removing the line when you click the delete button your plugin added:

Code: Select all
JiwaFinancials.Jiwa.JiwaStockTake.StockTakeLine stockTakeLine = stockTakeFrom.StockTake.Manager.CollectionItemFactory.CreateCollectionItem<JiwaFinancials.Jiwa.JiwaStockTake.StockTakeLine>();
stockTakeLine.RecID = grdLines.get_GridText("Key", e.Row).ToString();            
stockTakeLine.DeleteFlag = true;            
                     
stockTakeFrom.StockTake.StockTakeLines.Remove(stockTakeLine);


It's creating a new stock take line, setting the RecID to be the RecID corresponding to the line of the grid row, and then setting that *brand new* line's DeleteFlag to True, and then calling the Remove method of the StockTakeLines collection.

It appears to work, as the line is removed from the grid because the form receives an event that a line was removed, and it dutifully finds the line with the corresponding RecID in the grid and removes it.

But then you go to save, it's encountering now a line which was never added to be deleted. When you call Remove() on a JiwaCollection it takes the item passed and adds it to a DeletedCollection. That collection is what we look at to remove from the database on save. It's encountering an item which was not ever added to anything, and as such gets a null reference on some properties that are normally set when added - namely the StockTakeLines property which is a property fronting the Collection property.

You can fix this by replacing those 4 lines in your code with this:

Code: Select all
JiwaFinancials.Jiwa.JiwaStockTake.StockTakeLine stockTakeLine = stockTakeFrom.StockTake.StockTakeLines[grdLines.get_GridText("Key", e.Row).ToString()];                  
stockTakeFrom.StockTake.StockTakeLines.Remove(stockTakeLine);


It's getting the item you are wanting to delete from the StockTakeLines JiwaCollection, and passing it to the Remove method. This is the way we delete from JiwaCollections everywhere - always have. This will then mean that on save the right items are in the DeletedCollection with the right properties set, so no error occurs on Save().


You can always engage us to write plugins for you instead of you fumbling about hallucinating random solutions. We do charge money, but our plugins work.
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: 2583
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 807

Re: Deleting a stock take line

Postby Riyaz » Thu Aug 14, 2025 1:19 pm

Thanks Mike

Appreciate it, and yes we always reach out for complex plugins as we prefer Jiwa doing it, for these simple ones we dont mind getting our hands dirty considering we also learn at the same time.
Riyaz
Kohai
Kohai
 
Posts: 254
Joined: Wed Dec 02, 2015 2:05 pm
Topics Solved: 2


Return to Technical and or Programming

Who is online

Users browsing this forum: No registered users and 3 guests