Page 1 of 1

Lock SO 'Expected Delivery' Date

PostPosted: Thu Dec 17, 2015 2:39 pm
by 2can2
Hi, I am setting ExpectedDate = SO.InitiatedDate in Private Sub SOSaveEnd(sender As Object, e As EventArgs) as below

Private Sub SOSaveEnd(sender As Object, e As EventArgs)
SO.InitiatedDate = SO.ExpectedDeliveryDate
End Sub

However on Save the SaveIcon is always highlighted? If I close the SO and say Save changes it updates correctly!

2nd Part - I also want to LOCK 'Expected Delivery'. I have code to lock Custom grid but can't get this filed to work.

V129. Thanks.

Re: Lock SO 'Expected Delivery' Date  Topic is solved

PostPosted: Thu Dec 17, 2015 7:50 pm
by Mike.Sheen
2can2 wrote:Hi, I am setting ExpectedDate = SO.InitiatedDate in Private Sub SOSaveEnd(sender As Object, e As EventArgs) as below

Private Sub SOSaveEnd(sender As Object, e As EventArgs)
SO.InitiatedDate = SO.ExpectedDeliveryDate
End Sub

However on Save the SaveIcon is always highlighted? If I close the SO and say Save changes it updates correctly!


That code looks as though the intent is actually the opposite of what you are saying you want... plus it should be throwing an exception as your SOSaveEnd method has no knowledge of an "SO" variable, or object - you want to cast the sender as a type of SalesOrder - I can only assume we're talking sales order as you reference an InitiatedDate property and I think that's the only type we have with such a property.

SaveEnd occurs after the sales order is saved and all changes are committed to the database. Setting a property after that - as you are - will cause the changeflag to be set, and the UI to indicate that.

You really want to set any properties in the SaveStart event - then it will behave as you want.

2can2 wrote:2nd Part - I also want to LOCK 'Expected Delivery'. I have code to lock Custom grid but can't get this filed to work.

V129. Thanks.


The date control on the sales order form is called DTExpectedDeliveryDate - you will need to instruct that to be read-only at appropriate places - e.g.: salesOrderForm.DTExpectedDeliveryDate.Enabled = False. The appropriate places would whereever the form redisplays - in this case ReadEnd, CreateEnd and PropertyChanged.

Attached is a sample plugin which I believe does what you want.

NOTE:You can also disable fields for entry using the permissions system - you may want to consider that for locking the Expected Delivery date field, rather than having plugin code do it. If you ever start having conditions around which users can edit the field, then you should definitely use permissions.

Re: Lock SO 'Expected Delivery' Date

PostPosted: Fri Dec 18, 2015 6:45 pm
by 2can2
Thanks Mike - extremely helpful!