Sales Order Lines custom fields - make read only  Topic is solved

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

Sales Order Lines custom fields - make read only

Postby DannyC » Thu Sep 24, 2015 6:26 pm

Hi,

A slight variation to the post
http://forums.jiwa.com.au/viewtopic.php?f=26&t=406

I need to have a sales order line custom field which is read only.
Using the code in the above post I have been trying to make my custom field read only, but when I load sales order I get a Object reference not set to an instance of an object.

After spending a few days (!) trying to get this working, I need your assistance.
Plug in attached.
Attachments
Plugin Show Debtor_Debtor Class Disc on sales order lines.xml
(33 KiB) Downloaded 1288 times
User avatar
DannyC
Senpai
Senpai
 
Posts: 718
Joined: Fri Mar 22, 2013 12:23 pm
Topics Solved: 31

Re: Sales Order Lines custom fields - make read only

Postby Scott.Pearce » Tue Oct 20, 2015 2:14 pm

The grid is 0-based, so change your line:

Code: Select all
For lOrdLine = 1 To salesOrderForm.SalesOrder.SalesOrderLines.Count


to:

Code: Select all
For lOrdLine = 0 To salesOrderForm.SalesOrder.SalesOrderLines.Count - 1
Scott Pearce
Senior Analyst/Programmer
Jiwa Financials
User avatar
Scott.Pearce
Senpai
Senpai
 
Posts: 765
Joined: Tue Feb 12, 2008 11:27 am
Location: New South Wales, Australia
Topics Solved: 230

Re: Sales Order Lines custom fields - make read only

Postby DannyC » Thu Oct 22, 2015 8:09 pm

Thanks Scott,

One last problem. I am having trouble one of these lines
Code: Select all
   Dim salesOrderObject As JiwaFinancials.Jiwa.JiwaSales.SalesOrder.SalesOrder = DirectCast(sender, JiwaFinancials.Jiwa.JiwaSales.SalesOrder.SalesOrder)
      Dim salesOrderForm As JiwaFinancials.Jiwa.JiwaSalesUI.SalesOrder.SalesOrderEntryForm = DirectCast(sender, JiwaFinancials.Jiwa.JiwaSalesUI.SalesOrder.SalesOrderEntryForm)


Getting an error
Error: Unable to cast object of type 'JiwaFinancials.Jiwa.JiwaSalesUI.SalesOrder.SalesOrderEntryForm' to type 'JiwaFinancials.Jiwa.JiwaSales.SalesOrder.SalesOrder'
Module: LineDisplayed.

The whole sub is:
Code: Select all
   Sub LineDisplayed (sender As Object, e As System.EventArgs, SOLine As JiwaFinancials.Jiwa.JiwaSales.SalesOrder.SalesOrderLine)
       Dim salesOrderObject As JiwaFinancials.Jiwa.JiwaSales.SalesOrder.SalesOrder = DirectCast(sender, JiwaFinancials.Jiwa.JiwaSales.SalesOrder.SalesOrder)
      Dim salesOrderForm As JiwaFinancials.Jiwa.JiwaSalesUI.SalesOrder.SalesOrderEntryForm = DirectCast(sender, JiwaFinancials.Jiwa.JiwaSalesUI.SalesOrder.SalesOrderEntryForm)
      Dim lOrdLine As Integer       
         For lOrdLine = 0 To salesOrderForm.SalesOrder.SalesOrderLines.Count - 1
         For Each CustField As JiwaApplication.CustomFields.CustomField In SalesOrderObject.LineCustomFields
            salesOrderform.grdLines.LockColumn(True,CustField.PluginCustomField.GridColumnName,lOrdLine)
         Next
      Next
   End Sub
User avatar
DannyC
Senpai
Senpai
 
Posts: 718
Joined: Fri Mar 22, 2013 12:23 pm
Topics Solved: 31

Re: Sales Order Lines custom fields - make read only

Postby Scott.Pearce » Fri Oct 23, 2015 7:47 am

You are attempting to cast "sender" to a JiwaFinancials.Jiwa.JiwaSales.SalesOrder.SalesOrder in the first line, but sender is a form - specifically JiwaFinancials.Jiwa.JiwaSalesUI.SalesOrder.SalesOrderEntryForm. This line is invalid.

Then on the second line you are doing the correct thing, casting sender to a JiwaFinancials.Jiwa.JiwaSalesUI.SalesOrder.SalesOrderEntryForm.

Remove the first line.

If you want to get a sales order object then do this:

Code: Select all
Dim salesOrderObject As JiwaFinancials.Jiwa.JiwaSales.SalesOrder.SalesOrder = salesOrderForm.SalesOrder


After the line:

Code: Select all
Dim salesOrderForm As JiwaFinancials.Jiwa.JiwaSalesUI.SalesOrder.SalesOrderEntryForm = DirectCast(sender, JiwaFinancials.Jiwa.JiwaSalesUI.SalesOrder.SalesOrderEntryForm)
Scott Pearce
Senior Analyst/Programmer
Jiwa Financials
User avatar
Scott.Pearce
Senpai
Senpai
 
Posts: 765
Joined: Tue Feb 12, 2008 11:27 am
Location: New South Wales, Australia
Topics Solved: 230

Re: Sales Order Lines custom fields - make read only

Postby DannyC » Fri Oct 23, 2015 3:21 pm

I see. Got it.

Nearly there.
The first sales order when opening the module doesn't show any error, but the line custom field is not locked. It is still editable.
scrolling back to the previous sales order, which has > 1 line, comes up with an error re the index number. Any sales order with multiple lines will display the error.

Can you try importing the attached plugin and see where the issue is? I have tried various combinations but can't get the plugin in to work.
Attachments
Plugin Show Debtor Disc on sales order lines.xml
(33.33 KiB) Downloaded 1062 times
User avatar
DannyC
Senpai
Senpai
 
Posts: 718
Joined: Fri Mar 22, 2013 12:23 pm
Topics Solved: 31

Re: Sales Order Lines custom fields - make read only

Postby Mike.Sheen » Tue Oct 27, 2015 6:19 pm

This works for me:

Code: Select all
Sub LineDisplayed (sender As Object, e As System.EventArgs, SalesOrderLine As JiwaFinancials.Jiwa.JiwaSales.SalesOrder.SalesOrderLine)
   Dim salesOrderForm As JiwaSalesUI.SalesOrder.SalesOrderEntryForm =  DirectCast(sender, JiwaSalesUI.SalesOrder.SalesOrderEntryForm)
   Dim salesOrderObject As JiwaFinancials.Jiwa.JiwaSales.SalesOrder.SalesOrder = salesOrderForm.SalesOrder
       
   For lineNumber As Integer = 0 To salesOrderForm.SalesOrder.SalesOrderLines.Count - 1
      If salesOrderform.grdLines.GridText("Key", lineNumber) = SalesOrderLine.RecID Then
         For Each CustField As JiwaApplication.CustomFields.CustomField In SalesOrderObject.LineCustomFields
            salesOrderform.grdLines.LockColumn(True, CustField.PluginCustomField.GridColumnName, lineNumber)
         Next
         Exit For
      End If
   Next
End Sub
Attachments
Plugin Show Debtor Debtor Class Disc on sales order lines.xml
Modified plugin
(32.85 KiB) Downloaded 893 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: 2583
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 807

Re: Sales Order Lines custom fields - make read only

Postby DannyC » Wed Oct 28, 2015 4:22 pm

That's great Mike - thanks for the modded code.
I thought it was all sussed, but although I don't get any errors, the field is open for editing. There's no locking of that field to make it read only.

Would it be because I am deploying it to a site on version 125? Does it need to be a later version of Jiwa?

Cheers guys, really appreciate the help.

Danny
User avatar
DannyC
Senpai
Senpai
 
Posts: 718
Joined: Fri Mar 22, 2013 12:23 pm
Topics Solved: 31

Re: Sales Order Lines custom fields - make read only  Topic is solved

Postby Mike.Sheen » Sat Feb 27, 2016 5:51 pm

Bumping as was never marked as solved.
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: Sales Order Lines custom fields - make read only

Postby DannyC » Fri Mar 04, 2016 12:20 pm

Hi Mike,
I've deployed to my JiwaDemo database (7.0.149) & it looks fine. Not sure why it was not locking the field on the client data - maybe the version issue.
Anyway, have marked at solved.

cheers
User avatar
DannyC
Senpai
Senpai
 
Posts: 718
Joined: Fri Mar 22, 2013 12:23 pm
Topics Solved: 31


Return to Technical and or Programming

Who is online

Users browsing this forum: No registered users and 2 guests