Friday, December 1, 2023

Initializes form controls at runtime using X++ D365fo

/// <summary>
    /// Initializes LATAM form controls.
    /// </summary>
    /// <param name="_sender">The form run.</param>
    /// <param name="_args">The form event args.</param>
    [FormEventHandler(formStr(SalesEditLines), FormEventType::Initialized), SuppressBPWarning('BPParameterNotUsed', 'False positive')]
    public static void SalesEditLines_OnInitialized(xFormRun _sender, FormEventArgs _args)
    {
        if (!FeatureStateProvider::IsFeatureEnabled(LTMGlobalizationFeature::instance()))
        {
            return;
        }

        FormRun formRun = _sender;
        LTMSalesEditLines ltmSalesEditLines = formRun.parmLTMSalesEditLines();
        Struct controlsInv = new Struct();
        Struct controlsPS = new Struct();
        DocumentStatus documentStatus = formRun.args().caller().documentStatus();
        FormTabPageControl LTMTab = formRun.control(formRun.controlId(formControlStr(SalesEditLines, LTMTab)));

        // Dummies
        FormStringControl LTMPSBankGroupId =  LTMTab.addControl(FormControlType::String, 'LTMPSBankGroupId');
        FormComboBoxControl LTMPSCPDSource = LTMTab.addControl(FormControlType::ComboBox, 'LTMPSCPDSource');
        FormStringControl LTMPSControlCode =  LTMTab.addControl(FormControlType::String, 'LTMPSControlCode');
        FormStringControl LTMPSBeneficiary =  LTMTab.addControl(FormControlType::String, 'LTMPSBeneficiary');
        FormStringControl LTMPSHolderAccountNum =  LTMTab.addControl(FormControlType::String, 'LTMPSHolderAccountNum');
        FormRealControl LTMPSWithholdingBaseMST = LTMTab.addControl(FormControlType::Real, 'LTMPSWithholdingBaseMST');
        FormRealControl LTMPSWithholdAccruedAmountMST = LTMTab.addControl(FormControlType::Real, 'LTMPSWithholdAccruedAmountMST');
        FormRealControl LTMPSWithholdAccruedBaseMST = LTMTab.addControl(FormControlType::Real, 'LTMPSWithholdAccruedBaseMST');
        FormRealControl LTMPSAmountMST = LTMTab.addControl(FormControlType::Real, 'LTMPSAmountMST');
        FormRealControl LTMPSWithholdingEffectiveRate = LTMTab.addControl(FormControlType::Real, 'LTMPSWithholdingEffectiveRate');

        FormStringControl LTMInvBankGroupId =  LTMTab.addControl(FormControlType::String, 'LTMInvBankGroupId');
        FormComboBoxControl LTMInvCPDSource = LTMTab.addControl(FormControlType::ComboBox, 'LTMInvCPDSource');
        FormStringControl LTMInvControlCode =  LTMTab.addControl(FormControlType::String, 'LTMInvControlCode');
        FormStringControl LTMInvBeneficiary =  LTMTab.addControl(FormControlType::String, 'LTMInvBeneficiary');
        FormStringControl LTMInvHolderAccountNum =  LTMTab.addControl(FormControlType::String, 'LTMInvHolderAccountNum');
        FormRealControl LTMInvWithholdingBaseMST = LTMTab.addControl(FormControlType::Real, 'LTMInvWithholdingBaseMST');
        FormRealControl LTMInvWithholdAccruedAmountMST = LTMTab.addControl(FormControlType::Real, 'LTMInvWithholdAccruedAmountMST');
        FormRealControl LTMInvWithholdAccruedBaseMST = LTMTab.addControl(FormControlType::Real, 'LTMInvWithholdAccruedBaseMST');
        FormRealControl LTMInvAmountMST = LTMTab.addControl(FormControlType::Real, 'LTMInvAmountMST');
        FormRealControl LTMInvWithholdingEffectiveRate = LTMTab.addControl(FormControlType::Real, 'LTMInvWithholdingEffectiveRate');

        LTMPSBankGroupId.visible(false);
        LTMPSCPDSource.visible(false);
        LTMPSControlCode.visible(false);
        LTMPSBeneficiary.visible(false);
        LTMPSHolderAccountNum.visible(false);
        LTMPSWithholdingBaseMST.visible(false);
        LTMPSWithholdAccruedAmountMST.visible(false);
        LTMPSWithholdAccruedBaseMST.visible(false);
        LTMPSAmountMST.visible(false);
        LTMPSWithholdingEffectiveRate.visible(false);

        LTMInvBankGroupId.visible(false);
        LTMInvCPDSource.visible(false);
        LTMInvControlCode.visible(false);
        LTMInvBeneficiary.visible(false);
        LTMInvHolderAccountNum.visible(false);
        LTMInvWithholdingBaseMST.visible(false);
        LTMInvWithholdAccruedAmountMST.visible(false);
        LTMInvWithholdAccruedBaseMST.visible(false);
        LTMInvAmountMST.visible(false);
        LTMInvWithholdingEffectiveRate.visible(false);
       
        ltmSalesEditLines.parmForm(formRun.form());
        ltmSalesEditLines.parmTabLTM(formRun.control(formRun.controlId(formControlStr(SalesEditLines, LTMTab))));
        ltmSalesEditLines.parmSelectedTableAux(0);
        ltmSalesEditLines.parmDocumentStatus(documentStatus);
        ltmSalesEditLines.parmProforma(formRun.args().caller().proforma());
        ltmSalesEditLines.parmCheckLTM(formRun.control(formRun.controlId(formControlStr(SalesEditLines, LTMPrintFormLetter))));
        ltmSalesEditLines.parmPrimaryDS(formRun.dataSource(formDataSourceStr(SalesEditLines, SalesParmTable)));
        ltmSalesEditLines.parmExtendDS(formRun.dataSource(formDataSourceStr(SalesEditLines, LTMSalesParmTableJour)));
        ltmSalesEditLines.parmExtendDS2(formRun.dataSource(formDataSourceStr(SalesEditLines, LTMSalesParmTablePS)));
        ltmSalesEditLines.parmGroupJour(formRun.control(formRun.controlId(formControlStr(SalesEditLines, LTMInvoiceGrp))));
        ltmSalesEditLines.parmGroupPS(formRun.control(formRun.controlId(formControlStr(SalesEditLines, LTMPackingSlipGrp))));
        
        // Packing Slip
        controlsPS.add(LTMTransBasicConst::LTMDocumentClassificationId, formRun.control(formRun.controlId(formControlStr(SalesEditLines, LTMPSVoucherClassId))));
        controlsPS.add(LTMTransBasicConst::LTMSalesPointId, formRun.control(formRun.controlId(formControlStr(SalesEditLines, LTMPSSalesPointId))));
        controlsPS.add(LTMTransBasicConst::LTMSalesPointPrefix, formRun.control(formRun.controlId(formControlStr(SalesEditLines, LTMPSSalesPointPrefix))));
        controlsPS.add(LTMTransBasicConst::LTMDocumentNum, formRun.control(formRun.controlId(formControlStr(SalesEditLines, LTMPSDocumentNum))));
        controlsPS.add(LTMTransBasicConst::LTMCompleteDocumentNum, formRun.control(formRun.controlId(formControlStr(SalesEditLines, LTMPSCompleteDocumentNum))));
        controlsPS.add(LTMTransBasicConst::LTMDocumentDate, formRun.control(formRun.controlId(formControlStr(SalesEditLines, LTMPSDocumentDate))));
        controlsPS.add(LTMTransBasicConst::LTMCAICAEDueDate, formRun.control(formRun.controlId(formControlStr(SalesEditLines, LTMPSCAICAEDueDate))));
        controlsPS.add(LTMTransBasicConst::LTMDueDate, formRun.control(formRun.controlId(formControlStr(SalesEditLines, LTMPSDueDate))));
        controlsPS.add(LTMTransBasicConst::LTMCAICAE, formRun.control(formRun.controlId(formControlStr(SalesEditLines, LTMPSCAICAE))));
        controlsPS.add(LTMTransBasicConst::LTMCountryDocTypeId, formRun.control(formRun.controlId(formControlStr(SalesEditLines, LTMPSCountryDocTypeId))));
        controlsPS.add(LTMTransBasicConst::LTMCountryDocNum, formRun.control(formRun.controlId(formControlStr(SalesEditLines, LTMPSCountryDocNum))));
        controlsPS.add(LTMTransBasicConst::LTMBussinessName, formRun.control(formRun.controlId(formControlStr(SalesEditLines, LTMPSName))));
        controlsPS.add(LTMTransBasicConst::LTMConcept1, formRun.control(formRun.controlId(formControlStr(SalesEditLines, LTMPSConcept1))));
        controlsPS.add(LTMTransBasicConst::LTMConcept2, formRun.control(formRun.controlId(formControlStr(SalesEditLines, LTMPSConcept2))));
        controlsPS.add(LTMTransBasicConst::LTMConcept3, formRun.control(formRun.controlId(formControlStr(SalesEditLines, LTMPSConcept3))));
        controlsPS.add(LTMTransBasicConst::LTMFieldList01, formRun.control(formRun.controlId(formControlStr(SalesEditLines, LTMPSListField01))));
        controlsPS.add(LTMTransBasicConst::LTMFieldList02, formRun.control(formRun.controlId(formControlStr(SalesEditLines, LTMPSListField02))));
        controlsPS.add(LTMTransBasicConst::LTMFieldList03, formRun.control(formRun.controlId(formControlStr(SalesEditLines, LTMPSListField03))));
        controlsPS.add(LTMTransBasicConst::LTMFieldList04, formRun.control(formRun.controlId(formControlStr(SalesEditLines, LTMPSListField04))));
        controlsPS.add(LTMTransBasicConst::LTMFieldList05, formRun.control(formRun.controlId(formControlStr(SalesEditLines, LTMPSListField05))));
        controlsPS.add(LTMTransBasicConst::LTMFieldList06, formRun.control(formRun.controlId(formControlStr(SalesEditLines, LTMPSListField06))));
        controlsPS.add(LTMTransBasicConst::LTMFieldList07, formRun.control(formRun.controlId(formControlStr(SalesEditLines, LTMPSListField07))));
        controlsPS.add(LTMTransBasicConst::LTMFieldList08, formRun.control(formRun.controlId(formControlStr(SalesEditLines, LTMPSListField08))));
        controlsPS.add(LTMTransBasicConst::LTMFieldList09, formRun.control(formRun.controlId(formControlStr(SalesEditLines, LTMPSListField09))));
        controlsPS.add(LTMTransBasicConst::LTMFieldList10, formRun.control(formRun.controlId(formControlStr(SalesEditLines, LTMPSListField10))));
        controlsPS.add(LTMTransBasicConst::CountryRegionId,formRun.control(formRun.controlId(formControlStr(SalesEditLines, LTMPSCountryRegionId))));
        controlsPS.add(LTMTransBasicConst::StateId,formRun.control(formRun.controlId(formControlStr(SalesEditLines, LTMPSStateId))));
        controlsPS.add(LTMTransBasicConst::LTMStateDocTypeId,formRun.control(formRun.controlId(formControlStr(SalesEditLines, LTMPSStateDocTypeId))));
        controlsPS.add(LTMTransBasicConst::LTMStateDocNum,formRun.control(formRun.controlId(formControlStr(SalesEditLines, LTMPSStateDocNum))));
        controlsPS.add(LTMTransBasicConst::LTMTaxPayerTypeId,formRun.control(formRun.controlId(formControlStr(SalesEditLines, LTMPSTaxPayerTypeId))));

        // Dummy fields
        controlsPS.add(LTMTransBasicConst::BankGroupId,LTMPSBankGroupId);
        controlsPS.add(LTMTransBasicConst::LTMCPDSource,LTMPSCPDSource);
        controlsPS.add(LTMTransBasicConst::LTMControlCode,LTMPSControlCode);
        controlsPS.add(LTMTransBasicConst::LTMBeneficiary,LTMPSBeneficiary);
        controlsPS.add(LTMTransBasicConst::LTMHolderAccountNum,LTMPSHolderAccountNum);
        controlsPS.add(LTMTransBasicConst::LTMWithholdingBaseMST,LTMPSWithholdingBaseMST);
        controlsPS.add(LTMTransBasicConst::LTMWithholdAccruedAmountMST,LTMPSWithholdAccruedAmountMST);
        controlsPS.add(LTMTransBasicConst::LTMWithholdAccruedBaseMST,LTMPSWithholdAccruedBaseMST);
        controlsPS.add(LTMTransBasicConst::AmountMST,LTMPSAmountMST);
        controlsPS.add(LTMTransBasicConst::LTMWithholdingEffectiveRate,LTMPSWithholdingEffectiveRate);
        
        // Invoice
        controlsInv.add(LTMTransBasicConst::LTMDocumentClassificationId, formRun.control(formRun.controlId(formControlStr(SalesEditLines, LTMInvVoucherClassId))));
        controlsInv.add(LTMTransBasicConst::LTMSalesPointId, formRun.control(formRun.controlId(formControlStr(SalesEditLines, LTMInvSalesPointId))));
        controlsInv.add(LTMTransBasicConst::LTMSalesPointPrefix, formRun.control(formRun.controlId(formControlStr(SalesEditLines, LTMInvSalesPointPrefix))));
        controlsInv.add(LTMTransBasicConst::LTMDocumentNum, formRun.control(formRun.controlId(formControlStr(SalesEditLines, LTMInvDocumentNum))));
        controlsInv.add(LTMTransBasicConst::LTMCompleteDocumentNum, formRun.control(formRun.controlId(formControlStr(SalesEditLines, LTMInvCompleteDocumentNum))));
        controlsInv.add(LTMTransBasicConst::LTMDocumentDate, formRun.control(formRun.controlId(formControlStr(SalesEditLines, LTMInvDocumentDate))));
        controlsInv.add(LTMTransBasicConst::LTMCAICAEDueDate, formRun.control(formRun.controlId(formControlStr(SalesEditLines, LTMInvCAICAEDueDate))));
        controlsInv.add(LTMTransBasicConst::LTMDueDate, formRun.control(formRun.controlId(formControlStr(SalesEditLines, LTMInvDueDate))));
        controlsInv.add(LTMTransBasicConst::LTMCAICAE, formRun.control(formRun.controlId(formControlStr(SalesEditLines, LTMInvCAICAE))));
        controlsInv.add(LTMTransBasicConst::LTMControlCode, formRun.control(formRun.controlId(formControlStr(SalesEditLines, LTMControlCode))));
        controlsInv.add(LTMTransBasicConst::LTMCountryDocTypeId, formRun.control(formRun.controlId(formControlStr(SalesEditLines, LTMInvCountryDocTypeId))));
        controlsInv.add(LTMTransBasicConst::LTMCountryDocNum, formRun.control(formRun.controlId(formControlStr(SalesEditLines, LTMInvCountryDocNum))));
        controlsInv.add(LTMTransBasicConst::LTMBussinessName, formRun.control(formRun.controlId(formControlStr(SalesEditLines, LTMInvName))));
        controlsInv.add(LTMTransBasicConst::LTMConcept1, formRun.control(formRun.controlId(formControlStr(SalesEditLines, LTMInvConcept1))));
        controlsInv.add(LTMTransBasicConst::LTMConcept2, formRun.control(formRun.controlId(formControlStr(SalesEditLines, LTMInvConcept2))));
        controlsInv.add(LTMTransBasicConst::LTMConcept3, formRun.control(formRun.controlId(formControlStr(SalesEditLines, LTMInvConcept3))));
        controlsInv.add(LTMTransBasicConst::LTMFieldList01, formRun.control(formRun.controlId(formControlStr(SalesEditLines, LTMInvListField01))));
        controlsInv.add(LTMTransBasicConst::LTMFieldList02, formRun.control(formRun.controlId(formControlStr(SalesEditLines, LTMInvListField02))));
        controlsInv.add(LTMTransBasicConst::LTMFieldList03, formRun.control(formRun.controlId(formControlStr(SalesEditLines, LTMInvListField03))));
        controlsInv.add(LTMTransBasicConst::LTMFieldList04, formRun.control(formRun.controlId(formControlStr(SalesEditLines, LTMInvListField04))));
        controlsInv.add(LTMTransBasicConst::LTMFieldList05, formRun.control(formRun.controlId(formControlStr(SalesEditLines, LTMInvListField05))));
        controlsInv.add(LTMTransBasicConst::LTMFieldList06, formRun.control(formRun.controlId(formControlStr(SalesEditLines, LTMInvListField06))));
        controlsInv.add(LTMTransBasicConst::LTMFieldList07, formRun.control(formRun.controlId(formControlStr(SalesEditLines, LTMInvListField07))));
        controlsInv.add(LTMTransBasicConst::LTMFieldList08, formRun.control(formRun.controlId(formControlStr(SalesEditLines, LTMInvListField08))));
        controlsInv.add(LTMTransBasicConst::LTMFieldList09, formRun.control(formRun.controlId(formControlStr(SalesEditLines, LTMInvListField09))));
        controlsInv.add(LTMTransBasicConst::LTMFieldList10, formRun.control(formRun.controlId(formControlStr(SalesEditLines, LTMInvListField10))));
        controlsInv.add(LTMTransBasicConst::LTMInvEnablePS, formRun.control(formRun.controlId(formControlStr(SalesEditLines, LTMInvEnablePS))));
        controlsInv.add(LTMTransBasicConst::CountryRegionId,formRun.control(formRun.controlId(formControlStr(SalesEditLines, LTMInvCountryRegionId))));
        controlsInv.add(LTMTransBasicConst::StateId,formRun.control(formRun.controlId(formControlStr(SalesEditLines, LTMInvStateId))));
        controlsInv.add(LTMTransBasicConst::LTMStateDocTypeId,formRun.control(formRun.controlId(formControlStr(SalesEditLines, LTMInvStateDocTypeId))));
        controlsInv.add(LTMTransBasicConst::LTMStateDocNum,formRun.control(formRun.controlId(formControlStr(SalesEditLines, LTMInvStateDocNum))));
        controlsInv.add(LTMTransBasicConst::LTMTaxPayerTypeId,formRun.control(formRun.controlId(formControlStr(SalesEditLines, LTMInvTaxPayerTypeId))));

        // Dummy fields
        controlsInv.add(LTMTransBasicConst::BankGroupId,LTMInvBankGroupId);
        controlsInv.add(LTMTransBasicConst::LTMCPDSource,LTMInvCPDSource);
        controlsInv.add(LTMTransBasicConst::LTMControlCode,LTMInvControlCode);
        controlsInv.add(LTMTransBasicConst::LTMBeneficiary,LTMInvBeneficiary);
        controlsInv.add(LTMTransBasicConst::LTMHolderAccountNum,LTMInvHolderAccountNum);
        controlsInv.add(LTMTransBasicConst::LTMWithholdingBaseMST,LTMInvWithholdingBaseMST);
        controlsInv.add(LTMTransBasicConst::LTMWithholdAccruedAmountMST,LTMInvWithholdAccruedAmountMST);
        controlsInv.add(LTMTransBasicConst::LTMWithholdAccruedBaseMST,LTMInvWithholdAccruedBaseMST);
        controlsInv.add(LTMTransBasicConst::AmountMST,LTMInvAmountMST);
        controlsInv.add(LTMTransBasicConst::LTMWithholdingEffectiveRate,LTMInvWithholdingEffectiveRate);

        ltmSalesEditLines.parmControlsSalesEditLines(controlsPS, controlsInv);
        ltmSalesEditLines.init();
        ltmSalesEditLines.parmLTMReArrangeNow(false);
    }

No comments:

Post a Comment

Table browser URL in D365FO

Critical Thinking icon icon by Icons8