12-30-2011 11:15 PM
I am attempting to auto-update some field values in the Add/Edit Product window when certain values change. The problem, however, is that the event (OpportunityProduct.Fields.FieldChanged)
that looks like it ought to be firing on a value change is not firing. Below is my code. Any ideas?
Thanks.
private Dictionary<OpportunityProduct, MutableEntity.FieldCollection.FieldChangedHandler> _handlers; void OnCurrentOpportunityChanged(object sender, EventArgs e) { if (_handlers != null) { foreach (KeyValuePair<OpportunityProduct, MutableEntity.FieldCollection.FieldChangedHandler> kv in _handlers) { kv.Key.Fields.FieldChanged -= kv.Value; } _handlers.Clear(); } _handlers = new Dictionary<OpportunityProduct, MutableEntity.FieldCollection.FieldChangedHandler>(); foreach (OpportunityProduct oppProduct in _application.ApplicationState.CurrentOpportunity.GetProducts(null)) { MutableEntity.FieldCollection.FieldChangedHandler handler = new MutableEntity.FieldCollection.FieldChangedHandler(OnFieldsChanged); oppProduct.Fields.FieldChanged += handler; _handlers.Add(oppProduct, handler); } } void OnFieldsChanged(string fieldName) { bool b = true; }
01-03-2012 12:14 PM
01-03-2012 01:22 PM
Yes. We have added a custom read-only field that, when other fields are updated, this field will display a calculated value based on other fields in the window.
Could be the case about the commit, but it doesn't seem so. After I close the Add/Edit Product window, it doesn't fire. And if I then change the current opportunity, it doesn't fire. So, I would think (though I don't know) that it ought to be committed by then to the database.
01-03-2012 01:46 PM
Well, from the sound of it, it would seem that you need the "ValueChanged" event of the actual control that is being typed into. This would mean being able to hook into the UI itself for that screen, and I don't know if that's possible or not. If it is possible, then the sky's the limit so to speak. There may be other/better methods of accomplishing this task, I just don't know them.
*Feature Request* If the UI can't be hooked into (at a read-only level), it should. It would allow for a lot more customization, and result in more powerful/useful add-ins.