Skip to main content

Notifications

Announcements

No record found.

Finance | Project Operations, Human Resources, ...
Unanswered

Extension on standard form

Posted on by 419
[ExtensionOf(formDataSourceStr(InventJournalName, InventJournalName))]
internal final class DTT_InventJournalName_F_Extension
{
    public int active()
    {
        int ret = next active();
        InventJournalName InventJournalNameloc = this.cursor();
        if(InventJournalNameloc.JournalType == InventJournalType::Count || InventJournalNameloc.JournalType == InventJournalType::Movement)
        {
            this.object(fieldNum(InventJournalName,DTT_SiteMandatory)).allowEdit(true);
        }
        else
        {
            this.object(fieldNum(InventJournalName,DTT_SiteMandatory)).allowEdit(false);
        }
        return ret;
    }
}
 
 
 
 
static final class DTT_InventJournalNameEventHandler_F_Extension
{
    [FormDataSourceEventHandler(formDataSourceStr(InventJournalName, InventJournalName), FormDataSourceEventType::Activated)]
    public static void Table_OnActivated(FormDataSource sender, FormDataSourceEventArgs e)
    {
        
        InventJournalName        _table    = sender.cursor();
        FormDataSource            table_ds=sender.formRun().dataSource(/InventJournalName/);
        FormRun                   element      = sender.formRun();
        FormControl               ControlName =element.design(0).controlName(/DTT_SiteNotMandatory_DTT_SiteMandatory/);
       
       
     /*   if(_table.JournalType == InventJournalType::Count || _table.JournalType == InventJournalType::Movement)
            ControlName.allowEdit(true);
        else
            ControlName.allowEdit(false);*/
    }
   
}
 
 
 
 
[ExtensionOf(classStr(InventCountCreate))]
public final class DTT_InventCountCreate_C_Extension
{
    public DialogField dialogSplit;
    public DTT_SplitJournalPerWarehouse splitPerWarehouse;
    public JournalId journalIdToCreate;
    #DEFINE.CurrentVersion(10)
    #LOCALMACRO.CurrentList
         splitPerWarehouse
    #ENDMACRO
    public Object dialog()
    {
        InventJournalName inventJournalName;
        InventJournalTable inventJournalTableForDialog = InventJournalTable::find(this.parmJournalId());
        DialogRunbase thisDialog = next dialog();
        inventJournalName = inventJournalTableForDialog.inventJournalName();
        dialogSplit = thisDialog.addField(extendedTypeStr(DTT_SplitJournalPerWarehouse));
        if(inventJournalName.DTT_SiteMandatory == NoYes::Yes)
        {
            if (!inventJournalTableForDialog.InventLocationId)
            {
                dialogSplit.value(true);
                dialogSplit.allowEdit(true);
            }
        }
        else 
        {
            dialogSplit.value(false);
            dialogSplit.allowEdit(false);
        }
        return thisDialog;
    }
    public boolean getFromDialog()
    {
        boolean ret = next getFromDialog();
        splitPerWarehouse = dialogSplit.value();
        return ret;
    }
    public container pack()
    {
        container packedClassLocal = next pack();
        return SysPackExtensions::appendExtension(packedClassLocal, classStr(DTT_InventCountCreate_C_Extension), this.myPack());
    }
    public boolean unpack(container _packedClass)
    {
        boolean result = next unpack(_packedClass);
        if (result)
        {
            container myState = SysPackExtensions::findExtension(_packedClass, classStr(DTT_InventCountCreate_C_Extension));
            //Also unpack the extension
            if (!this.myUnpack(myState))
            {
                result = false;
            }
        }
        return result;
    }
    private container myPack()
    {
        return [#CurrentVersion, #CurrentList];
    }
    private boolean myUnpack(container _packedClass)
    {
        Integer version = RunBase::getVersion(_packedClass);
        switch (version)
        {
            case #CurrentVersion:
                [version, #CurrentList] = _packedClass;
                break;
            default:
                return false;
        }
        return true;
    }
    public void run()
    {
        next run();
        if (splitPerWarehouse)
        {
            this.splitJournalPerWarehouse();
        }
    }
    public void splitJournalPerWarehouse()
    {
        InventJournalTable fromInventJournalTable = InventJournalTable::find(this.parmJournalId());
        InventJournalTrans inventJournalTrans;
        InventDim inventDim;
        
        // To loop on how many unique warehouses from the journal
        while select inventDim
            group by InventLocationId
            exists join inventJournalTrans
                where inventJournalTrans.JournalId == this.parmJournalId()
                    && inventJournalTrans.InventDimId == inventDim.inventDimId
        {
            this.createNewHeader(fromInventJournalTable);
            this.createNewLines(inventDim.InventLocationId);
            this.postProcessing(inventDim.InventLocationId);
        }
        this.deleteLinesFromHeaderAndUpdateHeaderNumOfLines();
    }
    public void createNewHeader(InventJournalTable _fromInventJournalTable)
    {
        if (_fromInventJournalTable)
        {
            InventJournalTable toInventJournalTable;
            toInventJournalTable.data(_fromInventJournalTable);
            toInventJournalTable.JournalId = NumberSeq::newGetNum(InventParameters::numRefInventJournalId(),false).num();
            toInventJournalTable.SessionId = 0;
            toInventJournalTable.SessionLoginDateTime = utcDateTimeNull();
            toInventJournalTable.RecId = 0;
            toInventJournalTable.NumOfLines = 0;
            toInventJournalTable.SystemBlocked = NoYes::No;
            if (toInventJournalTable.validateWrite())
            {
                toInventJournalTable.insert();
                journalIdToCreate = toInventJournalTable.JournalId;
            }
        }
    }
    public void createNewLines(InventLocationId _inventLocationId)
    {
        InventJournalTrans inventJournalTransLines;
        InventDim inventDimLines;
        int lineCounter;
        // To loop the lines in the original journal and add it to a separate journal base on the grouping of warehouse
        while select inventJournalTransLines
            join inventDimLines
            where inventJournalTransLines.JournalId == this.parmJournalId()
                && inventJournalTransLines.InventDimId == inventDimLines.inventDimId
                && inventDimLines.InventLocationId == _inventLocationId
        {
            lineCounter++;
            InventJournalTrans inventJournalTransToCreate;
            inventJournalTransToCreate.data(inventJournalTransLines);
            inventJournalTransToCreate.JournalId = journalIdToCreate;
            inventJournalTransToCreate.LineNum = lineCounter;
            inventJournalTransToCreate.RecId = 0;
            if (inventJournalTransToCreate.validateWrite())
            {
                inventJournalTransToCreate.insert();
            }
        }
    }
    public void postProcessing(InventLocationId _inventLocationId)
    {
        this.updateHeaderNumOfLines(_inventLocationId);
    }
    public void updateHeaderNumOfLines(InventLocationId _inventLocationId)
    {
        InventJournalTable inventJournalTableLocal;
        InventJournalTrans inventJournalTransLocal;
        select count(RecId) from inventJournalTransLocal
            where inventJournalTransLocal.JournalId == journalIdToCreate;
        if (inventJournalTransLocal.RecId)
        {
            inventJournalTableLocal = InventJournalTable::find(journalIdToCreate);
            // This should have a value, but just to make sure
            if (inventJournalTableLocal)
            {
                ttsbegin;
                inventJournalTableLocal.selectForUpdate(true);
                inventJournalTableLocal.NumOfLines = inventJournalTransLocal.RecId; // To assign the number of lines to the header
                inventJournalTableLocal.update();
                ttscommit;
                Info(strFmt(/@Deloitte:DTT_CountingJournalForWarehouseInfo/, journalIdToCreate, _inventLocationId));
            }
        }
    }
    public void deleteLinesFromHeaderAndUpdateHeaderNumOfLines()
    {
        InventJournalTrans inventJournalTransToDelete;
        InventJournalTable inventJournalTableToUpdate;
        delete_from inventJournalTransToDelete
            where inventJournalTransToDelete.JournalId == this.parmJournalId();
        inventJournalTableToUpdate = InventJournalTable::find(this.parmJournalId());
        if (inventJournalTableToUpdate)
        {
            ttsbegin;
            inventJournalTableToUpdate.selectForUpdate(true);
            inventJournalTableToUpdate.NumOfLines = 0;
            inventJournalTableToUpdate.update();
            ttscommit;
        }
    }
}
  • André Arnaud de Calavon Profile Picture
    André Arnaud de Cal... 291,280 Super User 2024 Season 2 on at
    Extension on standard form
    Hi Pankaj,
     
    Please update the thread if you have an actual question where you would need help from the community.
  • Martin Dráb Profile Picture
    Martin Dráb 230,214 Most Valuable Professional on at
    Extension on standard form
    Hi Pankaj, please explain your problem; just showing some code without any explanation is not enough for helping you.
     
    By the way, I moved your thread from Dynamics AX forum to this forum about F&O.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans