C1CalcEngine Field or variable did not found

Posted by: levanduyet on 4 December 2023, 4:24 pm EST

  • Posted 4 December 2023, 4:24 pm EST

    I have a DataTable, the DataTable (dtResult) is from:

    SELECT itemprod
    	,version
    	,itemreq
    	,FORMAT(Quantity, '0.00000000') AS [Quantity]
    	,FORMAT(CostPriceStandard, '0') AS [TotalCostPrice]
    FROM tbBOM


    so I set datasource to C1CalcEngine as following:

    C1CalcEngine _calcEngine = new C1CalcEngine();
                        _calcEngine.DataSource = dtResult;
                        _calcEngine.Expression = "=Sum([Quantity]*[TotalCostPrice])";
                        var vTotal = _calcEngine.TryEvaluate(out object result) ? result.ToString() :
                                  _calcEngine.GetErrors().FirstOrDefault()?.FullMessage ?? "";


    The vTotal return “Col 5: Field or variable did not found.

    But when I check in immediate window, that I have value as following:

    dtResult.Columns[“Quantity”][1]

    “1.00000000”

    dtResult.Columns[“TotalCostPrice”][1]

    “164551”

    I don’t know how to fix it.

    These 2 column that exist in the dtResult DataTable.

    What should I do.

    Thanks,

    Duyet Le

  • Posted 5 December 2023, 8:31 pm EST - Updated 6 December 2023, 4:07 pm EST

    Hi Duyet,

    Thank you for sharing the code snippet. We could see the behavior you mentioned on our end. We are getting in touch with the development team to get their insights on this and will let you know the updates as soon as possible. [Internal Tracking ID: C1DCN-1088]

    In the meantime, to fix the behavior, instead of assigning the DataTable as the DataSource, you can assign the DataView as follows:

    C1CalcEngine _calcEngine = new C1CalcEngine();
    _calcEngine.DataSource = dtResult.DefaultView;
    _calcEngine.Expression = "=Sum([Quantity]*[TotalCostPrice])";
    var vTotal = _calcEngine.TryEvaluate(out object result) ? result.ToString() : _calcEngine.GetErrors().FirstOrDefault()?.FullMessage ?? "";

    Please see the attached sample project for reference (CalcEngineSample.zip).

    Best Regards,

    Kartik

  • Posted 9 December 2023, 1:13 am EST

    Hi Kartik,

    Any news about this issue.

    Thanks,

    Duyet Le

  • Posted 10 December 2023, 3:05 pm EST

    Hi Duyet,

    We are getting in touch with the development team to get an update on this and will let you know as soon as possible. In the meantime, we recommend you continue your work using the way we suggested in our previous response.

    Thank you for your patience.

    Kind Regards,

    Kartik

  • Posted 10 December 2023, 10:09 pm EST

    Hi Duyet,

    As per the development team, this behavior will be fixed in the upcoming 2023v3 hotfix release. The ETA for this release is 30-45 days from now. In the meantime, you can use the workaround that we suggested earlier (DataTable.DefaultView property).

    Best Regards,

    Kartik

  • Posted 12 December 2023, 1:28 am EST

    Thanks Kartik.

    Duyet Le

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels