Overwrite value on method created formRealControl

Here is how I am trying to update a value to be a custom value from the CostingVersion Table. This control does not contain a datasource. It is a method that runs off the form BOMCalcDialog. It is getting the correct information but when I test the code. It doesn't change to what is expected. It shows 1 not 5 which is what variable "qty" equals. Why isn't it committing the change and displaying 5 on the form instead?

[FormEventHandler(formStr(BOMCalcDialog), FormEventType::Initialized)]
    public static void BOMCalcDialog_OnInitialized(xFormRun sender, FormEventArgs e)
    {
        FormRealControl itemqty = sender.design().controlName("itemQty");
        itemqty.autoDeclaration(true);
        FormStringControl costVer = sender.design().controlName("VersionId");
        str version = costVer.valueStr();
        CostingVersion costingVersion;
        select * from costingVersion
            where costingVersion.VersionId == version;
        ProductQuantity qty = costingVersion.MJMChargesQty;
        itemqty.realValue(qty);
    }

Related
Recommended