RE: Capturing field value change using C#
Thank you Richard, I got it and will look into it more. But you can try using these two lines as mentioned by David, it will change batch id value and also prompt for adding batch. Let us know if it is also working for you.
Dynamics.Forms.SopEntry.SopEntry.BatchNumber.Value = "Test";
Dynamics.Forms.SopEntry.SopEntry.BatchNumber.RunValidate();
Even in earlier case when you were pressing the save button it has to prompt the new batch message as when you focus on any other field , you actually tab out from batch field (means focus out ) and then message should be prompted. I think it may not be prompting because of the event you are setting batch value from, I will try to run your code to confirm this.
About using Focus() and Clear()
Their use is not inessential, but I would say they are significant and good practice. As it is not known exactly when you are setting up the batch ID value and at that time where you current focus is, so it's better to focus the field your are going to set a value for.
- The focus statement can move the focus to the fields, and always runs the post script of the current field and the pre script for the new field so in this way we are save to complete all the necessary script/codes of current field and pre script of new field (if there is any).
- If also help to work correctly when we don't know exactly where the current field lead us as per tab sequence defined, like sometimes when we return value from lookups they don't ended up on the lookup field but set focus to some other field.
- The focus statement moves the focus to the specified field. This statement can be used to skip unnecessary fields in a window, or to place the focus in a specific field after an event.
- It is normal practice in dexterity to clear fields before setting new values and throughout you can see in dexterity manual.
RunValidate() is equivalent of dexterity 'force change'. ( as appears to me).
The force change statement causes the field change script to be run when the user moves the focus out of the field, whether or not the field has changed. This statement should be used only for the field where the focus is currently positioned.