Translate

Saturday, August 10, 2019

Open Sales Order Clouse Custom Form in Ax 2012 X++

 

Open Sales Order Clouse Custom Form in Ax 2012 X++




Form Methods:

public class FormRun extends ObjectRun
{
    QueryBuildRange         headerVoided;
    QueryBuildRange         headerType;
    QueryBuildRange         headerProjId;
    QueryBuildRange         lineVoided;

    TransDate               toDate;

    InventDimCtrl_Frm_Mov   inventDimFormSetup;

    SalesLine               salesLinelocal;
}

void checkSelectAllBox()
{
    ;

    if(!Salesline_CheckSelected.Value())
    {
        SelectAll.checked(False);
    }
}

public Common docCursor()
{
    Common docCursor;

    docCursor = super();

    if (docCursor.TableId == tablenum(InventDim))
    {
        docCursor = salesLine;
    }

    return docCursor;
}
void init()
{
    super();

    toDate = mkDate(1, (mthOfYr(systemDateget())), year(systemDateget()));

    salesTable_ds.query().dataSourceTable(tablenum(SalesTable)).addRange(fieldnum(SalesTable, SalesStatus)).value(queryValue(SalesStatus::Backorder));
    salesLine_ds.query().dataSourceTable(tablenum(SalesLine)).addRange(fieldnum(SalesLine, SalesType)).value(queryValue(SalesType::ReturnItem));
    salesLine_ds.query().dataSourceTable(tablenum(SalesLine)).addRange(fieldnum(SalesLine, SalesType)).value(queryValue(SalesType::Sales));
    salesLine_ds.query().dataSourceTable(tablenum(SalesLine)).addRange(fieldnum(SalesLine, SalesType)).value(queryValue(SalesType::Subscription));
    salesLine_ds.query().dataSourceTable(tablenum(SalesLine)).addRange(fieldnum(SalesLine, SalesStatus)).value(queryValue(SalesStatus::Backorder));

    //salesLine_ds.query().dataSourceTable(tablenum(SalesLine)).addRange(fieldnum(SalesLine, ConfirmedDlv)).value(queryValue(strFmt("<%1", toDate)));

    element.updateDesign(InventDimFormDesignUpdate::Init);

    if (element.args().record())
    {
        salesLine_ds.object(fieldnum(SalesLine, CustAccount)).visible(False);
    }
}

Object inventDimSetupObject()
{
    return inventDimFormSetup;
}

void selectAllRecord()
{
    SalesIdBase salesIdBase;
    LineNum     lineNumberLoc;
    ;

    ttsbegin;

    for (salesLineLocal = SalesLine_ds.getFirst(); salesLineLocal != null; salesLineLocal = salesLine_ds.getNext())
    {
        salesIdBase = salesLineLocal.SalesId;
        lineNumberLoc = salesLinelocal.LineNum;
        salesLinelocal = SalesLine::find(salesIdBase, lineNumberLoc);
        salesLinelocal.selectForUpdate(true);

        if (SelectAll.value() == NoYes::Yes)
        {
            salesLinelocal.CheckSelected = NoYes::Yes;
        }
        else
        {
            salesLinelocal.CheckSelected = NoYes::No;
        }

        salesLinelocal.Update();
    }

    ttscommit;
}

void updateDesign(InventDimFormDesignUpdate mode)
{
    InventMovement movement = InventMovement::construct(salesLine);

    switch (mode)
    {
        case InventDimFormDesignUpdate::Init :
            if (!inventDimFormSetup)
            {
                inventDimFormSetup  = InventDimCtrl_Frm_Mov::newFromFormMovement(element, movement);
            }

        case InventDimFormDesignUpdate::Active :
          //  inventDimFormSetup.formActiveSetup(movement.inventTable().DimGroupId,movement);
            inventDimFormSetup.formSetControls(true);
            break;

        case InventDimFormDesignUpdate::FieldChange :
           // inventDimFormSetup.formActiveSetup(movement.inventTable().DimGroupId,movement);
            inventDimFormSetup.formSetControls(false);
            break;

        default : throw error(strfmt("@SYS54195",funcname()));
    }
}

void updateSelectedRecord()
{

    DialogButton dialogButton;
    int countSelected;
    ;

    dialogButton = box::yesNo("Do you want to short close deliver remainders for the selected lines", dialogButton::Yes, "@SYS116321");

    if (dialogButton == dialogButton::Yes)
    {
        ttsbegin;

        for (salesLineLocal = salesLine_ds.getFirst(); salesLineLocal != null ;salesLineLocal = salesLine_ds.getNext())
        {
            if (salesLineLocal.CheckSelected == NoYes::Yes)
            {
                salesLinelocal = SalesLine::find(salesLinelocal.SalesId, salesLinelocal.LineNum);
                salesLinelocal.selectForUpdate(true);

                salesLinelocal.RemainSalesPhysical = 0;
                salesLinelocal.RemainInventPhysical = 0;
                salesLinelocal.CheckSelected = NoYes::No;

                salesLinelocal.Update();

                countSelected++;
            }
        }

        ttscommit;

        if (countSelected)
        {
            info(strfmt("%1 seleted rows updated",countSelected));
        }
        else
        {
            info(strfmt("No rows were selected"));
        }
    }
}

FormDataSource salesTable_ds()
{
    return salesTable_ds;
}

public void modified()
{
    super();

    element.checkSelectAllBox();
}

public void clicked()
{
    super();

    element.selectAllRecord();

    SalesLine_ds.reread();
    SalesLine_ds.research();
    SalesLine_ds.refresh();
}

void clicked()
{
    super();

    element.updateSelectedRecord();

    SalesLine_ds.reread();
    SalesLine_ds.research();
    SalesLine_ds.refresh();
}

Adding "Code commented by your Name, Date" comments in existing method using x++

 \Classes\EditorScripts


Add new below method.

class EditorScripts
{
}

void MaheshCommentStart(Editor e)
{
          e.insertLines('//New code added by Mahesh'+ ' on ' + 'Begin:' + ' ' + date2str(today
          (),123,2,1,3,1,4 ) +  ''   +' at ' + time2str(timeNow(), 1, 1) + '\n');
}

void MaheshCommentEnd(Editor e)
{
          e.insertLines('//New code added by Mahesh'+ ' on ' + 'End:' + ' ' + date2str(today
          (),123,2,1,3,1,4 ) +  ''   +' at ' + time2str(timeNow(), 1, 1) + '\n');
}


Go to customizing object methods -> Right Click -> Scripts -> Add and enjoy.



Friday, July 26, 2019

Cannot create a record in Product Modeling Policy (EcoResProductMasterModelingPolicy). Reference: 0, No. The record already exists. In AX 2012 R3

 DIXF Product entity returns the following error for every product. 

Explanation

DIXF Product entity loaded data into target data sources based on descending sequence number (DMFTargetEntityHierarchy.SequenceNo), and EcoResProductMasterModelingPolicy is the first table to get loaded (Seq. No. 22 out of 22 target data sources).


However, records cannot be inserted into EcoResProductMasterModelingPolicy if it does not have a valid ProductMaster.RecId available for reference.

This makes sense since EcoResProductMasterModelingPolicy is getting populated before EcoResProduct (which also populates EcoResProductMaster to provide a RecId). 

Solution

To fix this, I changed the seq. no. of EcoResProduct to 23, making it the largest value so it will get selected and populated first in the while loop.




static void EcoResProductSequenceUpdate(Args _args)

{

    DMFTargetEntityHierarchy DMFTargetEntityHierarchy;

    select forupdate DMFTargetEntityHierarchy

        where DMFTargetEntityHierarchy.recid == 5637145349;

    if (DMFTargetEntityHierarchy)

    {

        ttsbegin;

        DMFTargetEntityHierarchy.SequenceNo = 23;

        DMFTargetEntityHierarchy.doupdate();

        info('done');

        ttsCommit;

    }

}

Wednesday, June 26, 2019

Open a Purchtable form through info log in AX 2012

How to open Purchtable form from the Info Log.

static void viewPOthroughInfo(Args _args)
{
    PurchTable  purchTable;
 
    purchTable = PurchTable::find("PO-000001852");
 
    info(strFmt("@PAC51058",purchTable.PurchId),"", SysInfoAction_TableField::newBuffer(purchTable));
}


Now click and show button, it will navigate to Purchtable form for the PO number.

 

Job to get distinct display product number in D365FO

 In this blog, I will discuss how to get a distinct display product number in Dynamics 365 Finance and Operations. Please see the screenshot below with the source code explanation.


Note: In my case, I have got Item Id and Invent Dim Id from RFQ Lines.

Explanation of source code (1.1):
  • Get a purchase request for quotation from RFQCaseId and LineNum.
  • Updating inventory dimensions.
  • Find or create an inventory dimension.
  • Find the inventory dimension combination is order to get the product variant record ID.
  • Get the display product number and set it in the info method.

class JobToGetDisplayProductNumber
{
    /// <summary>
    /// In this job we are getting display product number by
    /// Item Id and Invent Dim Id.
    /// </summary>
    /// <param name = "args">The specified arguments.</param>
    public static void main(Args _args)
    {

        PurchRFQCaseLine         line;

        InventDim                inventDim;
        InventDimCombination     inventDimComb;
 
        //Get purchase request for quotation line from RFQId and LineNum
        line = PurchRFQCaseLine::find('CDPL-000051', 3);
         
        //Updating inventory dimensions
        inventDim = line.inventDim();
        inventDim.InventSiteId = '';
        inventDim.InventLocationId = '';
 
        //Find or Create inventory dimensions
        inventDim = InventDim::findOrCreate(inventDim);
 
        //Find inventory dimension combination in order to get Product Variant Record Id
        inventDimComb = InventDimCombination::findByInventDim(line.ItemId, inventDim);

 

        //Display product from <c>EcoResDistinctProductVariant</c> table.
        info(EcoResDistinctProductVariant::find(inventDimComb.DistinctProductVariant).DisplayProductNumber);
    }
}