Dynamics AX Blog - Dynamics AX 2012 - Page 13

These posts are machine-translated.
Currently, only posts are displayed, which are relevant for Dynamics AX version »Dynamics AX 2012« Filter entfernen

RSS-Feed of this version

AX 2012: How to change the value of a default dimension of a record

The following job will give you an example, of how to change the value of a dimension within the default dimensions of a record (the example-job changes the value of the dimension costcenter of a customer). In this way and manner individual dimension values can be removed also.

static void changeDimensionValue(Args _args)
{
    DimensionAttributeValueSetStorage dimensionAttributeValueSetStorage;
    DimensionAttribute dimensionAttribute;
    CustTable custTable = CustTable::find("US-014");
    DimensionValue oldDimensionValue;
    DimensionValue newDimensionValue = "011";
    DimensionDefault newDimensionDefault;

    #define.dimensionName("CostCenter")

    DimensionValue getDimensonValue(DimensionDefault _dimensionDefault)
    {
        DefaultDimensionView defaultDimensionView;
        select firstonly DisplayValue
        from defaultDimensionView
        where defaultDimensionView.Name == #dimensionName
            && defaultDimensionView.DefaultDimension == _dimensionDefault;

        return defaultDimensionView.DisplayValue;
    }

    // Get current value
    oldDimensionValue = getDimensonValue(custTable.DefaultDimension);

    // Build DimensionAttributeValueSetStorage
    dimensionAttributeValueSetStorage = DimensionAttributeValueSetStorage::find(custTable.DefaultDimension);
 
    // Remove old dimension value
    dimensionAttribute = DimensionAttribute::findByName(#dimensionName);
    dimensionAttributeValueSetStorage.removeDimensionAttributeValue(
        DimensionAttributeValue::findByDimensionAttributeAndValue(dimensionAttribute, oldDimensionValue).RecId);
 
    // Set new dimension value
    if(newDimensionValue != "")
    {
        dimensionAttribute = DimensionAttribute::findByName(#dimensionName);
        dimensionAttributeValueSetStorage.addItem(
            DimensionAttributeValue::findByDimensionAttributeAndValue(dimensionAttribute, newDimensionValue));
    }
 
    newDimensionDefault = dimensionAttributeValueSetStorage.save();

    ttsbegin;
    custTable.selectForUpdate(true);
    custTable.DefaultDimension = newDimensionDefault;
    custTable.update();
    ttscommit;
}

Screenshot before job

Screenshot

Screenshot after job

Screenshot


 
 

Create a picking list line for a production order

The following job creates a picking list line for a production order.

static void createProdJournalBOM(Args _args)
{
    AxProdJournalBOM axProdJournalBOM;
    InventDim inventDim;

    axProdJournalBOM = AxProdJournalBOM::construct();
    axProdJournalBOM.validateInput(true);
    axProdJournalBOM.continueOnError(true);

    axProdJournalBOM.parmProdId("P000194");
    axProdJournalBOM.parmJournalId("00950");
    axProdJournalBOM.parmItemId("M0014");
    axProdJournalBOM.parmBOMConsump(30);
    axProdJournalBOM.prodJournalBOM().initFromInventTable(InventTable::find(axProdJournalBOM.parmItemId()));

    // Lagerungsdimensionen (optional)
    inventDim = axProdJournalBOM.prodJournalBOM().inventDim();
    inventDim.InventSizeId = "1000";
    inventDim = InventDim::findOrCreate(inventDim);
    axProdJournalBOM.parmInventDimId(inventDim.InventDimId);

    axProdJournalBOM.save();
}

 
 

Find number sequence code based on Exteneded data type

I recently had a problem with a number sequence in a form. But i didn't know the name of the number sequence, so i was not able to look for it in the number sequence code form.
So, I wrote the following job, which determined the number sequence code on the basis of the EDTs of the field from my form. Thus the number sequence was quickly found and i could solve the problem.

info(strFmt("%1", NumberSequenceTable::find(
    NumberSeqReference::findReference(
         extendedTypeNum(PurchReqId)).NumberSequenceId).NumberSequence));

 
 

Reserve/Unreserve a sales order line

The are a lot of examples about how to reserve a sales order line. But i did not find an example, where the result of the reservation has been tested.

So i had to write some code for my own. I am checking the reserved value before executing my code, and afterwards. If the reserved quantity is still the same, my job seems to have failed.

static void reserveSalesLine(Args _args)
{
    InventTransIdSumSingleStatus inventTransIdSumSingleStatus;
    SalesLine salesLine;
    InventMovement inventMovement;
    InventDim inventDim;
    InventDimParm inventDimParmCriteria;
    InventQtyReservPhysical oldReservedQty;
    InventQtyReservPhysical newReservedQty;
    InventUpd_Reservation inventUpd_Reservation;
    InventQty reserveQty;

    // Inline method to get current reserved quantity for specific inventDim
    InventQtyReservPhysical getReservedQty()
    {
        inventDimParmCriteria.initFromInventDim(inventDim);        

        inventTransIdSumSingleStatus = InventTransIdSumSingleStatus::newTransOriginIdStatus(InventTransOriginSalesLine::findInventTransOriginId(salesLine.DataAreaId, salesLine.InventTransId),
                                                                                            StatusReceipt::None,
                                                                                            StatusIssue::ReservPhysical);
        inventTransIdSumSingleStatus.parmInventDimCriteria(inventDim);
        inventTransIdSumSingleStatus.parmInventDimParmCriteria(inventDimParmCriteria);

        return inventTransIdSumSingleStatus.reservPhysical();
    }

    // Sales order line
    salesLine = SalesLine::findInventTransId('012431');
    inventMovement = InventTrans::findTransId(salesLine.InventTransId).inventMovement(true);

    // Build inventDim-Record, where the quantity should be reserved
    inventDim.clear();
    inventDim.InventSiteId      = "1";
    inventDim.InventLocationId  = "12";
    inventDim.wmsLocationId     = "12";
    inventDim = InventDim::findOrCreate(inventDim);

    // Get current physical reserved Quantity
    oldReservedQty = getReservedQty();

    // Set quanity which should be reserved (negative values to reserve, postive value to unreserve)
    reserveQty = -2;

    inventUpd_Reservation = InventUpd_Reservation::newInventDim(inventMovement,
                                                                inventDim,
                                                                reserveQty,
                                                                true);
    inventUpd_Reservation.updateNow();

    // Get new reserved quantity
    newReservedQty = getReservedQty();

    // Compare old and new reserved quantity to identify if reservation failed
    if(oldReservedQty == newReservedQty)
    {
        error("Reservation failed.");
    }
}

 
 

Check/Post a picking list journal for a production order

Below is a sample of X++ code which can be used to check or post a picking list journal for a production order. Changing the value of the Enum JournalCheckPostType controls if the journal is checked or checked and posted.

static void checkPostProdJournalTablePickingList(Args _args)
{
    JournalCheckPost journalCheckPost;
    ProdJournalTable prodJournalTable = ProdJournalTable::find("00943", true);

    // Check/Post journal
    journalCheckPost = ProdJournalCheckPostBOM::newJournalCheckPost(false,
                                                                    true,
                                                                    JournalCheckPostType::Check,
                                                                    prodJournalTable.TableId,
                                                                    prodJournalTable.JournalId);
    journalCheckPost.run();
}

 
 

Check/Post a route card journal for a production order

Below is a sample of X++ code which can be used to check or post a route card journal for a production order. Changing the value of the Enum JournalCheckPostType controls if the journal is checked or checked and posted.

static void checkPostProdJournalTableRoute(Args _args)
{
    JournalCheckPost journalCheckPost;
    ProdJournalTable prodJournalTable = ProdJournalTable::find("00943", true);

    // Check/Post journal
    journalCheckPost = ProdJournalCheckPostRoute::newJournalCheckPost(false,
                                                                    true,
                                                                    JournalCheckPostType::Check,
                                                                    prodJournalTable.TableId,
                                                                    prodJournalTable.JournalId);
    journalCheckPost.run();
}

 
 

Check/Post a job card journal for a production order

Below is a sample of X++ code which can be used to check or post a job card journal for a production order. Changing the value of the Enum JournalCheckPostType controls if the journal is checked or checked and posted.

static void checkPostProdJournalTableRouteJob(Args _args)
{
    JournalCheckPost journalCheckPost;
    ProdJournalTable prodJournalTable = ProdJournalTable::find("00943", true);

    // Check/Post journal
    journalCheckPost = ProdJournalCheckPostRouteJob ::newJournalCheckPost(false,
                                                                    true,
                                                                    JournalCheckPostType::Check,
                                                                    prodJournalTable.TableId,
                                                                    prodJournalTable.JournalId);
    journalCheckPost.run();
}

 
 
Pages « 1 ... 10 11 12 13 14 15 16 ... 22 » 

 

 
 
 
Posts of the actual month
April 2024
MoTuWeThFrSaSu
1234567
891011121314
15161718192021
22232425262728
2930 
 
© 2006-2024 Heinz Schweda | Imprint | Contact | German version | Mobile version
In order to provide you with better service, this site uses cookies. By continuing to browse the site, you are agreeing to our use of cookies.