Sunday, April 11, 2021

Show progress window and refresh the caller form after execution

/// <summary>
    /// gets the parameter
    /// </summary>
    /// <param name = "_args"></param>
    static void main(Args _args)
    {
        container       inputParameters;
        SalesTable      salesTable;

        if (_args && _args.record())
        {
            try
            {
                salesTable = _args.record();

                inputParameters = [salesTable.SalesId];

                SysOperationSandbox::callStaticMethod(classNum(SalesCalculateCumulativeGrossWeight), staticMethodStr(SSalesCalculateCumulativeGrossWeight, calculate), inputParameters, "Sales:SalesOrderGrossWeightCalculationMessage", "@SYS9265");

                SalesCalculateCumulativeGrossWeight::refreshCallingForm(_args);
            }
            catch (Exception::Error)
            {
                error ("@SYS138340");
            }
            catch (Exception::CLRError)
            {
                //Access the last CLR Exception
                error (CLRInterop::getLastException().ToString());
            }
        }
    }

    /// <summary>
    /// Refresh SalesTable form datasources after calculation
    /// </summary>
    /// <param name = "_args"></param>
    static void refreshCallingForm(args _args)
    {
        if (_args && _args.caller() && _args.caller() is formRun)
        {
            FormRun callerFormRun = _args.caller() as formRun;

            if(callerFormRun.name() ==  formStr(SalesTable))
            {
                //SalesTabe
                callerFormRun.dataSource(1).research(true);
                callerFormRun.dataSource(1).refresh();

                //SalesLine
                callerFormRun.dataSource(2).research(true);
                callerFormRun.dataSource(2).refresh();
            }
        }
    }

No comments:

Post a Comment

Table browser URL in D365FO

Critical Thinking icon icon by Icons8