Creating and revising the Project Budget from Project Forecasts in D365FFO – AX – X++

With the following code we can able to import the project budget and revising too

    MenuItemName                actionName;
    MenuFunction                menuFunction;
    Args                        args = new args();
    IProjBudgetGridUpdatable    projBudgetGridUpdatable;
    ProjBudget                  projBudget,ProjBudgetWFStatus,projBudgetRec;
    ProjBudgetLine              projBudgetLine,PBL;
    projBudgetRevision          projBudgetRevision;
    projBudgetRevisionLine      projBudgetRevisionLine;
    ProjBudgetAllocationLine    projBudgetAllocationLine;
    ForecastModelId             defaultModelIdForForecastImport;
    FormDataSource              projBudget_ds,ProjBudgetLineRevenue_ds,ProjBudgetLineCost_ds;
    ProjBudgetImportBatch       projBudgetImportBatch = new ProjBudgetImportBatch();


    args = new Args();
    actionName = menuitemActionStr(projBudgetImportBatch);

    ttsbegin;

    projbudget::findOrCreateProjectBudget("HH");
    Select forupdate projBudget where projBudget.RootProjId == "HH";
    if(projBudget.BudgetWorkflowStatus == ProjBudgetWorkflowStatus::Created)
    {

        projBudgetImportBatch.parmProjId("HH");
        projBudgetImportBatch.parmProjBudgetRecId(projBudget.RecId);
        projBudgetImportBatch.parmSource("CurrentF");
        projBudgetImportBatch.parmMarkValue(0);
        projBudgetImportBatch.parmProjBudgetImportOptions(ProjBudgetImportOptions::Units);
        projBudgetImportBatch.parmProjBaseBudgetOn(projbaseBudgetOn::Forecast);
        projBudgetImportBatch.parmSummarizeByCategory(noyes::Yes);
        projBudgetImportBatch.parmInBatch(noyes::No);
        args.parmObject(projBudgetImportBatch);
        menuFunction = new MenuFunction(actionName, MenuItemType::Action);
        menuFunction.run(args);
        projbudget::updateProjBudgetStatus(projBudget.RecId,ProjBudgetWorkflowStatus::Submitted);
        projbudget::updateProjBudgetStatus(projBudget.RecId,ProjBudgetWorkflowStatus::Approved);
        args.record(projbudget);
        args.parmEnumType(enumnum(ProjBudgetManagerActionType));
        args.parmEnum(ProjBudgetManagerActionType::Commit);
        ProjBudgetManager::main(args);

    }
    projBudgetLine.clear();
    projBudgetRec.clear();


    // Budget revision
    if(projBudget.BudgetWorkflowStatus == ProjBudgetWorkflowStatus::Approved)
    {
        projBudgetRevision::createRevision(projBudget.RecId);
        select ProjBudgetRevision  where ProjBudgetRevision.ProjBudget == projBudget.RecId;
        projBudgetImportBatch.parmProjId("HH");
        projBudgetImportBatch.parmProjBudgetRecId(projBudget.RecId);
        projBudgetImportBatch.parmProjBudgetRevisionRecId(projBudgetRevision.RecId);
        projBudgetImportBatch.parmSource("CurrentF");
        projBudgetImportBatch.parmMarkValue(0);
        projBudgetImportBatch.parmProjBudgetImportOptions(ProjBudgetImportOptions::Units);
        projBudgetImportBatch.parmProjBaseBudgetOn(projbaseBudgetOn::Forecast);
        projBudgetImportBatch.parmSummarizeByCategory(noyes::Yes);
        projBudgetImportBatch.parmInBatch(noyes::No);
        args.parmObject(projBudgetImportBatch);
        menuFunction = new MenuFunction(actionName, MenuItemType::Action);
        menuFunction.run(args);
        ProjBudgetRevision::updateProjBudgetRevisionStatus(ProjBudgetRevision.RecId,ProjBudgetRevisionWFStatus::Submitted);
        ProjBudgetRevision::updateProjBudgetRevisionStatus(ProjBudgetRevision.RecId,ProjBudgetRevisionWFStatus::Approved);
        args.record(ProjBudgetRevision);
        ProjBudgetRevisionManager::main(args);
        while select forupdate PBL where PBL.ProjId == "HH"
        {
            PBL.UncommittedRevisions =0;
            PBL.update();

            while select projBudgetRevisionLine where projBudgetRevisionLine.ProjBudgetRevision == ProjBudgetRevision.RecId
            {
                select forupdate projBudgetAllocationLine where projBudgetAllocationLine.ProjBudgetLine == PBL.RecId;
                projBudgetAllocationLine.CommittedRevisions = projBudgetRevisionLine.RevisionAmount;
                projBudgetAllocationLine.TotalAllocationAmount = projBudgetRevisionLine.NewTotalBudget;
                projBudgetAllocationLine.update();
            }
        }
    }

Rispondi

Inserisci i tuoi dati qui sotto o clicca su un'icona per effettuare l'accesso:

Logo di WordPress.com

Stai commentando usando il tuo account WordPress.com. Chiudi sessione /  Modifica )

Google photo

Stai commentando usando il tuo account Google. Chiudi sessione /  Modifica )

Foto Twitter

Stai commentando usando il tuo account Twitter. Chiudi sessione /  Modifica )

Foto di Facebook

Stai commentando usando il tuo account Facebook. Chiudi sessione /  Modifica )

Connessione a %s...