Page 1 of 1
Sales Order Lines custom fields - make read only

Posted:
Thu Sep 24, 2015 6:26 pm
by DannyC
Hi,
A slight variation to the post
http://forums.jiwa.com.au/viewtopic.php?f=26&t=406I 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.
Re: Sales Order Lines custom fields - make read only

Posted:
Tue Oct 20, 2015 2:14 pm
by Scott.Pearce
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
Re: Sales Order Lines custom fields - make read only

Posted:
Thu Oct 22, 2015 8:09 pm
by DannyC
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
Re: Sales Order Lines custom fields - make read only

Posted:
Fri Oct 23, 2015 7:47 am
by Scott.Pearce
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)
Re: Sales Order Lines custom fields - make read only

Posted:
Fri Oct 23, 2015 3:21 pm
by DannyC
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.
Re: Sales Order Lines custom fields - make read only

Posted:
Tue Oct 27, 2015 6:19 pm
by Mike.Sheen
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
Re: Sales Order Lines custom fields - make read only

Posted:
Wed Oct 28, 2015 4:22 pm
by DannyC
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
Re: Sales Order Lines custom fields - make read only 

Posted:
Sat Feb 27, 2016 5:51 pm
by Mike.Sheen
Bumping as was never marked as solved.
Re: Sales Order Lines custom fields - make read only

Posted:
Fri Mar 04, 2016 12:20 pm
by DannyC
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