Community
Showing results for 
Search instead for 
Do you mean 
Reply

OpportunityProduct Fields FieldChanged event not firing

New Member
Posts: 2
Country: USA

OpportunityProduct Fields FieldChanged event not firing

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;
}

 

Nickel Contributor
Posts: 175
Country: USA

Re: OpportunityProduct Fields FieldChanged event not firing

To verify your goal: you want some values to change in a window based on the information in other fields in said window. Correct?

If I am correct in my understanding, it may be that it isn't firing, because the field hasn't actually changed (read: committed to the database). Someone more experienced with the SDK could confirm/deny this. Just a thought.
New Member
Posts: 2
Country: USA

Re: OpportunityProduct Fields FieldChanged event not firing

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.

Nickel Contributor
Posts: 175
Country: USA

Re: OpportunityProduct Fields FieldChanged event not firing

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.