Skip to main content

Notifications

Microsoft Dynamics AX (Archived)

Create transfer order with a product which has variants

Posted on by Microsoft Employee

Hello

I'm trying to create transfer orders, like desrcibed in this post: 

https://community.dynamics.com/ax/b/mafsarkhan/archive/2011/04/14/creating-transfer-order-through-x-code

My problem is, that I have products with product variants and I can't get those working - for simple products the import already works

I don't know how to configure it correctly, I always get the error "Inventory dimension Configuration is a product dimension and must consequently be specified."

Here is my code:

    // Properties

    HcmWorker                               workerTable;
    HcmEmployment                           employmentTable;
    WEAHcmEmploymentWenatexDetail           employmentDetailTable;

    InventTransferTable                     inventTransferTable;
    InventTransferLine                      inventTransferLine;
    NumberSequenceReference                 numberSequenceReference;
    NumberSeq                               numberSeq;

    WTXImportAgentInventTransferPosition    positionTable;

    LogisticsLocation                       logisticsLocation;
    LogisticsPostalAddress                  logisticsPostalAddress;

    InventTable                             inventTable;
    InventDimCombination                    inventDimCombinationTable;
    InventDim                               inventDimTable;

    // Code
    while select validTimeState(currentDateTime, currentDateTime) workerTable
        join employmentTable
            where employmentTable.Worker == workerTable.RecId
        join employmentDetailTable
            where employmentDetailTable.Employment == employmentTable.RecId
                && workerTable.PersonnelNumber == baseTable.PersonnelNumber
    {
        if(employmentDetailTable && employmentDetailTable.InventLocationId)
        {
            break;
        }
    }

    if(!employmentDetailTable)
    {
        throw error("No storage found");
    }

    inventTransferTable.clear();
    inventTransferTable.initValue();
    numberSequenceReference = InventParameters::numRefTransferId();
    numberSeq = numberSeq::newGetNumFromCode(numberSequenceReference.numberSequenceTable().NumberSequence);
    inventTransferTable.TransferId = numberSeq.num();

    inventTransferTable.InventLocationIdFrom = baseTable.InventLocationIdFrom;
    inventTransferTable.modifiedField(fieldNum(InventTransferTable, InventLocationIdFrom));
    inventTransferTable.InventLocationIdTo = employmentDetailTable.InventLocationId;
    inventTransferTable.WEAToWMSLocationId = employmentDetailTable.WMSLocationId;
    inventTransferTable.modifiedField(fieldNum(InventTransferTable, InventLocationIdTo));
    inventTransferTable.WEAInventTransferType = WEAInventTransferType::SalesAgent;
    inventTransferTable.TransferStatus = InventTransferStatus::Created;
    inventTransferTable.WEAHcmWorkerRecId = workerTable.RecId;

    logisticsPostalAddress = DirParty::primaryPostalAddress(workerTable.Person);

    logisticsLocation = LogisticsLocation::find(logisticsPostalAddress.Location);

    if (logisticsLocation.RecId)
    {
        inventTransferTable.ToAddressName      = logisticsLocation.Description;
        inventTransferTable.ToPostalAddress    = LogisticsPostalAddress::addressRecIdFromLocationRecId(logisticsLocation.RecId);
    }

    inventTransferTable.insert();


    while select positionTable where positionTable.TransferBaseRecId == baseTable.RecId
    {
        productIdTable.clear();
        select productIdTable where productIdTable.LokiProductId == positionTable.ProductId;

        if(!productIdTable)
        {
            throw error(strFmt("No mapping for product [%1] found!", positionTable.ProductId));
        }

        inventTransferLine.clear();

        if(productIdTable.configId)
        {
            // InventDim
            inventDimTable.clear();
            inventDimTable.configId = productIdTable.configId;
            inventDimTable.InventLocationId = employmentDetailTable.InventLocationId;
            inventDimTable.InventSiteId = employmentDetailTable.InventSiteId;
            inventDimTable = InventDim::findOrCreate(inventDimTable);
            inventTransferLine.InventDimId = inventDimTable.inventDimId;

            // WEAToInventDim
            inventDimTable.clear();
            inventDimTable.configId = productIdTable.configId;
            inventDimTable.InventLocationId = baseTable.InventLocationIdFrom;
            inventDimTable.InventSiteId = baseTable.InventSiteIdFrom;
            inventDimTable = InventDim::findOrCreate(inventDimTable);
            inventTransferLine.WEAToInventDimId = inventDimTable.inventDimId;
        }

        inventTransferLine.ItemId = productIdTable.ItemId;
        inventTransferLine.initFromInventTable(InventTable::find(productIdTable.ItemId));
        inventTransferLine.initFromInventTransferTable(inventTransferTable, NoYes::Yes);
        inventTransferLine.QtyTransfer = positionTable.Quantity;
        inventTransferLine.QtyShipNow = 0;
        inventTransferLine.QtyReceiveNow = 0;
        inventTransferLine.QtyRemainShip = positionTable.Quantity;
        inventTransferLine.QtyRemainReceive = positionTable.Quantity;
        inventTransferLine.UnitId = positionTable.Unit;

        inventTransferLine.insert();
    }

Hope one can help me?!

Best regards

Jürgen Starkl

*This post is locked for comments

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,253 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans