Alfasith AX

Alfasith AX
اللَّهُمَّ انْفَعْنِي بِمَا عَلَّمْتَنِي، وَعَلِّمْنِي مَا يَنْفَعُنِي، وَزِدْنِي عِلْمًا

Wednesday, February 28, 2024

Dimension Lookup for both standard and Custom dimension in D365

Hi,


 /// <summary>

    /// Provides the look-up interaction for the individual dimension value lookup controls.

    /// </summary>

    /// <param name="_dimensionValueControl">

    /// The <c>FormStringControl</c> enumeration value that triggers this event.

    /// </param>

    /// <param name="_localizedName">

    /// The localized dimension attribute name

    /// </param>

    /// <param name="_promptErrorMessage">

    /// Whether prompt the error message if the dimension type is empty.

    /// </param>

    public static void dimensionValueLookup(

        FormStringControl   _dimensionValueControl,

        Name                _localizedName,

        boolean             _promptErrorMessage = false)

    {

        Query                   query = new Query();

        SysTableLookup          sysTableLookup;

        QueryBuildDataSource    qbds;


        DimensionAttribute      dimensionAttribute;

        RecId                   dimensionAttributeId;

        DataAreaId              dataAreaId = curext();


        if (_localizedName)

        {

            dimensionAttribute      = DimensionAttribute::findByLocalizedName(_localizedName, false, currentUserLanguage());

            dimensionAttributeId    = dimensionAttribute.RecId;

        }


        if (dimensionAttributeId)

        {

            sysTableLookup = SysTableLookup::newParameters(DimensionCache::instance().dimensionAttributeBackingTable(dimensionAttributeId), _dimensionValueControl);


            sysTableLookup.addLookupfield(dimensionAttribute.ValueAttribute);

            LedgerDimensionTranslationLookupHelper::addLookupTranslation(sysTableLookup, dimensionAttributeId);

            sysTableLookup.addSelectionField(dimensionAttribute.NameAttribute);


            changeCompany(dataAreaId)

            {

                qbds = query.addDataSource(DimensionCache::instance().dimensionAttributeBackingTable(dimensionAttributeId));

                qbds.addOrderByField(DimensionCache::instance().dimensionAttributeValueField(dimensionAttributeId));

                DimensionAttribute::restrictQueryToCategorizedValues(qbds, dimensionAttributeId);

            }


            sysTableLookup.parmQuery(query);

            sysTableLookup.performFormLookup();

        }

        else if (_promptErrorMessage)

        {

            //Please choose a value for "Dimension type" first!

            checkFailed("@GLS100015");

        }

    }


Regards


Tuesday, February 27, 2024

How to get enumValue from enumID in D365 (using SQl)

 Hi,


SELECT ENUMVALUETABLE.ENUMID, ENUMVALUETABLE.ENUMVALUE, ENUMVALUETABLE.NAME 

FROM ENUMVALUETABLE

INNER JOIN ENUMIDTABLE ON ENUMIDTABLE.ID = ENUMVALUETABLE.ENUMID

where ENUMIDTABLE.NAME = 'ProjOrigin'


Regards,

Friday, November 24, 2023

Auto submit of any process to Workflow in D365 / X++

 Hi,


        try
        {
            ttsbegin;
                        
            Workflow::activateFromWorkflowType( workFlowTypeStr( "workFlowTypeName"),  TableName.RecId, "Auto submitted by action Alfa", NoYes::No);
            
            ttscommit;
        }
        catch(exception::Error)
        {
            throw Error("Not submitted");
        }

///             _workflowCorrelationId = Workflow::activateFromWorkflowType( _workflowTypeName, _recId, "Comments", NoYes::No);
             

             IssueStateChangeManager::submit(TableBuffer);


Regards,

Auto Submit the pending vendor Invoice to workflow in D365

 /// <summary>
    /// Post open inventory journals
    /// </summary>
    public void run()
    {
        TradeLineRefId       headerReference;
        VendInvoiceInfoTable vendInvoiceInfoTable;
     
        //vendInvoiceInfoTable = VendInvoiceInfoTable::findTableRefId(headerReference);
 
        while (gQueryRun.next())
        {
            vendInvoiceInfoTable    = gQueryRun.get(tableNum(VendInvoiceInfoTable));
            try
            {
                if(this.validationWorkflowSubmit(vendInvoiceInfoTable))
                {
                    this.SubmitVendorInvoice(vendInvoiceInfoTable);
                }
            }
            
            catch (Exception::CLRError)
            {
                System.Exception interopException = CLRInterop::getLastException();
                error(strFmt("%1", interopException));
            }
            catch (Exception::Error)
            {
                error(strFmt("An error occured during the update."));
            }
        }
    }

    /// <summary>
    /// Validates if the workflow can be started.
    /// </summary>
    /// <returns>true if workflow can start</returns>
    private boolean validationWorkflowSubmit(vendInvoiceInfoTable   _vendInvoiceInfoTable)
    {
        // Don't submit if a posted invoice with the same invoice number already exists.
        if (!this.validateDuplicateInvoice(_vendInvoiceInfoTable))
        {
            throw Exception::error;
        }
                
        if (PublicSectorUtils::isBudgetReservationEnabled())
        {
            VendInvoiceInfoTable::checkBudgetReservationBalance_PSN(_vendInvoiceInfoTable.TableRefId, _vendInvoiceInfoTable.SourceDocumentHeader);
        }
        if (isConfigurationkeyEnabled(configurationKeyNum(Project)) && ProjFundingLimitTrackingManager::hasLimitErrorSourceDocument(_vendInvoiceInfoTable.SourceDocumentHeader))
        {
            throw error("@SYS4110061");
        }
        boolean areAccountingDistributionsValid;
        VendParameters vendParameters = VendParameters::find();
        if((Dynamics.AX.Application.FeatureStateProvider::isFeatureEnabled( AccountingDistributionWorkflowSubmissionFeature::instance()) && vendParameters.BypassValidationOfAccountingDistributions == NoYes::Yes)
            || SourceDocumentProvider::areSourceDocAccDistAccountValid( SourceDocumentHeader::find( _vendInvoiceInfoTable.SourceDocumentHeader), true, true))
        {
            areAccountingDistributionsValid = true;
        }
        if (!areAccountingDistributionsValid)
        {
            return false;
        }
        return true;
    }

    /// <summary>
    /// Determines if a posted invoice with the same invoice number already exists.
    /// </summary>
    /// <returns>
    /// True if a posted invoice with the same invoice number does not exist. False if already exists.
    /// </returns>
    private boolean validateDuplicateInvoice(VendInvoiceInfoTable  _vendInvoiceInfoTable)
    {
        boolean isInvoiceNumberFreeForUse = true;
        if (Dynamics.AX.Application.FeatureStateProvider::isFeatureEnabled( VendInvoiceRejectDuplicateNumOnWorkflowSubmitFeature::instance()))
        {
            VendTable localVendTable = VendTable::find(_vendInvoiceInfoTable.InvoiceAccount);
            if (!localVendTable.checkInvoice(_vendInvoiceInfoTable.Num, _vendInvoiceInfoTable.TransDate))
            {
                isInvoiceNumberFreeForUse = false;
            }
        }
        return isInvoiceNumberFreeForUse;
    }
    /// <summary>
    /// Creates the vendor invoice.
    /// </summary>
    public void SubmitVendorInvoice(VendInvoiceInfoTable  _vendInvoiceInfoTable)
    {
        workflowComment        workflowComment = "Auto submission to workflow.";
        //changecompany (custInvoice.ProjIntercompany)
        //{
        if (_vendInvoiceInfoTable.RecId
                && _vendInvoiceInfoTable.RequestStatus == VendInvoiceRequestStatus::Draft)
               // && custTable.interCompanyTradingPartner().interCompanyTradingRelation().Active
                //&& this.validationWorkflowSubmit())
            {
                VendInvoiceHeaderWorkflow::submitToWorkflow( _vendInvoiceInfoTable, workflowComment);
            }
        //}
    }


Thursday, November 9, 2023

CancelSuperCall in D365

 Hi,


Usually, based on the FormControlEventArgs e, the cancellation can be implemented using the following code snippets:


FormControlCancelableSuperEventArgs     eventArgs = e as FormControlCancelableSuperEventArgs;

eventArgs.CancelSuperCall();


In cases where there are no FormControlEventArgs, you are required to throw an error to halt the super process.

Thanks,

Get a table ID in SQL / table browser - D365

Hi select ID from SysTableIdView where  SysTableIdView .Name = 'CustTable' <URL>/?cmp=<CompanyID>&mi=sysTableBrowser...