[X++] BOF / SOF Change Query in dialog dynamically

Normally you have a DataContract with a method for your query and the SOF puts it to the dialog automatically and you do not have to worry about anything.

We all know how to override methods in a SOF Dialog (if not, don't worry i explain it later).
But what if you want to change your query depending on the selected value of a dialog field?

First of all, these are the methods in the DataContract:

[
    DataMemberAttribute,
    AifQueryTypeAttribute('_packedQuery', '')
]
public str parmPackedQuery(str _packedQuery = packedQuery)
{
    packedQuery = _packedQuery;

    return packedQuery;
}
public Query getQuery()
{
    return new Query(SysOperationHelper::base64Decode(packedQuery));
}
public void setQuery(Query _query)
{
     packedQuery = SysOperationHelper::base64Encode(_query.pack());
}

The UIBuilder class looks like this:

public class MyUIBuilder extends SysOperationAutomaticUIBuilder
{
    MyContract     contract;
    DialogField    df_MappingId;
    DialogField    df_Direction;
}
public void postBuild()
{
    super();

    contract        = this.dataContractObject();
    df_MappingId    = this.bindInfo().getDialogField(contract, methodStr(MyContract, parmMappingId));
    df_MappingId.registerOverrideMethod(methodStr(FormReferenceGroupControl, validate), methodStr(MyUIBuilder, mappingID_validate), this);
}
public boolean mappingID_validate(FormReferenceGroupControl _control)
{
    this.setNewQuery();

    return true;
}
public void setNewQuery()
{
    Query       newQuery;

    // get your query:
    newQuery = this.buildNewQuery();

    contract.setQuery(newQuery);
    // now here happens the update to the dialog:
    this.controller().putToDialog();
}

Now the dialog looks like this when openend:
Dialog opened

And if you change the value of Mapping ID:
updated query