DAXSPOT

Thursday, August 11, 2022

Error - cannot create record in DMFEntity in D365FO.

Hello,

Sometimes after developing a entity, user face "record already exist in Entity" error. This can be solved by simply deleting all records in DMFEntity table.

Once you refresh entity list. you will get all the entities back.

Either you can run the below job or just go to the DMFEntity Table and delete that one selected record which is causing the error.

There are a lot of other related error:

Severity    Code    Description    Project    File    Line    Suppression State

Error        Infolog diagnostic message: 'Error synching entity metadata for entity - KRTProductEntity. Message -    at Microsoft.Dynamics.Ax.MSIL.Interop.throwException(Int32 ExceptionValue, interpret* ip)            0    

Error        at Dynamics.AX.Application.DmfDataPopulation.syncEntityUpdate(DMFEntity dmfEntity, DictDataEntity dictDataEntity)            0    

Error        at Dynamics.AX.Application.DMFEntity.insert() in xppSource://Source/ApplicationFoundation\AxTable_DMFEntity.xpp:line 433            0    

Error        Infolog diagnostic message: 'Cannot create a record in Entity (DMFEntity). Entity: Items, KRTProductStaging.            0    

Error        at Dynamics.AX.Application.DmfDataPopulation.syncEntityUpdate(DMFEntity dmfEntity, DictDataEntity dictDataEntity, Boolean useTargetEntityName, Boolean @useTargetEntityName_IsDefaultSet) in xppSource://Source/ApplicationFoundation\AxClass_DmfDataPopulation.xpp:line 947            0    

Error        at Dynamics.AX.Application.DmfDataPopulation.syncEntityMetadata(StringCollection dataEntityViewCollection, StringCollection compositeEntityList) in xppSource://Source/ApplicationFoundation\AxClass_DmfDataPopulation.xpp:line 794.' on category 'Error'.            0    

Error        at Dynamics.AX.Application.DmfDataPopulation.syncEntityCreate(DictDataEntity dictDataEntity, Boolean useTargetEntityName, Boolean @useTargetEntityName_IsDefaultSet) in xppSource://Source/ApplicationFoundation\AxClass_DmfDataPopulation.xpp:line 899            0    

Error        at Dynamics.AX.Application.DmfDataPopulation.syncEntityCreate(DictDataEntity dictDataEntity, Boolean useTargetEntityName)            0    

Error        at Microsoft.Dynamics.Ax.Xpp.Common.Insert()            0    

Error        at Microsoft.Dynamics.Ax.MSIL.cqlCursorIL.insert(IntPtr table)            0    

Error        at Microsoft.Dynamics.Ax.Xpp.NativeCommonImplementation.Insert()            0    

Error        Database synchronization failed. You may have to do a full build of the package 'K3Retail' and all of its dependent packages.            0    

Error        The record already exists.' on category 'Error'.            0    


JOB Sample:

class DeleteDMFEntity

{        

    public static void main(Args _args)

    {      

        DMFEntity dmfEntity;

        DMFTargetXML dmfTargetXML;

 

         //ttsbegin;

        delete_from dmfEntity;

        delete_from dmfTargetXML;

 

         /*while select forupdate dmfEntity

        {

            dmfEntity.delete();

        }*/

        //ttscommit;

        info('Done');

    }

}

Thursday, August 4, 2022

Get invent onHand as per site/warehouse or InventDimId itself, using x++ code.

Hello,

This post will help you to get invent onHand as per site/warehouse or InventDimId itself.


InventDim inventDim;

InventDimParm inventDimParm;

InventOnHand inventOnHand;

ItemId itemId;

InventDimId inventDimId;


itemId  = "XYZ";

inventDim.InventSiteId = "XYZ";

inventDim.InventLocationId = "XYZ";

inventDimParm.initFromInventDim(inventDim);

inventOnHand = InventOnhand::newParameters(itemId, inventDim, inventDimParm);

inventOnHand.availPhysical();

//or 

inventDimId = "XYZ";

inventDim = InventDim::find(inventDimId); //you can use as SalesLine.InventDimId

inventDimParm.initFromInventDim(inventDim);

inventOnHand = InventOnhand::newParameters(itemId, inventDim, inventDimParm);

inventOnHand.availPhysical();


Happy Daxing!

Wednesday, August 3, 2022

Department for the current user in X++ select statement

Hi All,

Below you will find a snippet to get department for the current user.


select OMOperatingUnit 

            join HcmPositionDetail

                where OMOperatingUnit.RecId == HcmPositionDetail.Department

            join HcmPosition 

                where HcmPositionDetail.Position == HcmPosition.RecId

            join HcmPositionWorkerAssignment

                where HcmPosition.RecId == HcmPositionWorkerAssignment.Position

            join HcmWorker 

                where HcmPositionWorkerAssignment.Worker == HcmWorker.RecId

            join DirPerson 

                where HcmWorker.Person == DirPerson.RecId

            join DirPersonUser 

                where DirPersonUser.PersonParty == DirPerson.RecId 

                && DirPersonUser.User == curUserId();

Thursday, October 29, 2020

Append Text to String or append two texts to a string in X++

Hi All,

Simple way to concatenate String in x++ is using plus(+) sign or strFmt function.

List of concatenating methods in x++:

strFmt

str ss = strFmt('Name=%1, Surname=%2, Phone Number=%3', nameStr, surnameStr, phNum);

+ Sign

str ss = 'Name=' + nameStr+ ', Surname=' + surnameStr+ ', Phone Number=' + phNum;

System.String::Concat
System.String s1 = System.String::Concat('Name=', nameStr);
System.String s2 = System.String::Concat(', Surname=', surnameStr);
System.String s3 = System.String::Concat(', Phone Number=', phnNum);
System.String s4 = System.String::Concat(s2, s3, ', Gender=', genderStr);
str s5 = System.String::Concat(s1, s4);
System.Text.StringBuilder
System.Text.StringBuilder sb = new System.Text.StringBuilder();
   
sb.Append("Name=");
sb.Append(nameStr);
sb.Append(", Surname=");
sb.Append(surnameStr);
sb.Append(", Phone Number=");
sb.Append(phnNum);
str result = sb.ToString();
info(result);
The Result:
1000000 strFmt took 0.00 milliseconds in average, in total 3398
1000000 +ing took 0.00 milliseconds in average, in total 1843
1000000 System.String::Concat took 0.00 milliseconds in average, in total 655
1000000 System.Text.StringBuilder took 0.00 milliseconds in average, in total 896

Reference: http://devlicious.net/

Monday, October 19, 2020

show or hide the "Select" button in a parameter dialog when we run the report - SSRS Report

Hi,

This below code will help you to show or hide the "Select" button in a parameter dialog when we run the ssrs report.

We just need to add this method in controller class.
public  boolean  showQuerySelectButton(str parameterName)
{
    return false;
}

Friday, October 9, 2020

Pass a range of enum value - X++ Code

Hi,

Today i will be sharing the code to pass the range of a enum value while working in x++ query or adhoc query.

SalesTable_ds.query().dataSourceTable(tableNum(SalesTable)).addRange(fieldnum(SalesTable,SalesStatus)).value(sysquery::value(SalesTable::Invoiced));

Monday, October 5, 2020

Import from excel and create Sales Order with Multiple Sales Lines in ax 2012

Hi,

Below code will help to Import and create Sales Order with Multiple Lines in ax 2012.
This has some reference from other blogs.

SalesTable      salesTable;
SalesLine       salesLine;
InventDim       inventDim;
NumberSeq        num;
SysExcelApplication application;
SysExcelWorkbooks workbooks;
SysExcelWorkbook workbook;
SysExcelWorksheets worksheets;
SysExcelWorksheet worksheet,worksheet1;
SysExcelCells cells,cells1;
COMVariantType type;
int row;
;
application = SysExcelApplication::construct();
workbooks = application.workbooks();
workbooks.open('File Path \\SalesOrderCreate.xlsx'); //file path
workbook = workbooks.item(1);
worksheets = workbook.worksheets();
worksheet = worksheets.itemFromName("Header");
worksheet1 = worksheets.itemFromName("Lines");
cells = worksheet.cells();
cells1 = worksheet1.cells();
 
num = NumberSeq::newGetNum(SalesParameters::numRefSalesId());
salesTable.SalesId = num.num();
 
salesTable.CustAccount = cells.item(1,1).value().bStr();
salesTable.initValue(SalesType::Sales);
salesTable.initFromCustTable();
if(salesTable.validateWrite())
{
salesTable.insert();
}
 
do
{
row++;
inventDim.clear();
inventDim.InventSiteId = int2str(real2int(cells1.item(row,4).value().double()));
inventDim.InventLocationId = int2str(real2int(cells1.item(row,5).value().double()));
 
salesLine.clear();
salesLine.initValue(salesTable.SalesType);
salesLine.initFromSalesTable(salesTable);
salesLine.ItemId = cells1.item(row, 1).value().bStr();
salesLine.initFromInventTable(InventTable::find(cells1.item(row, 1).value().bStr()));
salesLine.InventDimId = InventDim::findOrCreate(inventDim).inventDimId;
salesLine.SalesQty = any2int(cells1.item(row,2).value().toString());
salesLine.RemainSalesPhysical = salesLine.SalesQty;
salesLine.SalesUnit = cells1.item(row,3).value().bStr();
salesLine.QtyOrdered = salesLine.calcQtyOrdered();
salesLine.RemainInventPhysical = salesLine.QtyOrdered;
salesLine.setPriceDisc(InventDim::find(salesLine.InventDimId));
 
type = cells1.item(row+1, 1).value().variantType();
if (salesLine.validateWrite())
{
salesLine.insert();
}
}
while (type != COMVariantType::VT_EMPTY);
 
workbooks.close();
application.quit();
 
info("Done!");

How to execute SQL directly form Dynamics AX X++

How to execute Sql directly form Dynamics AX X++ Reference by : alirazazaidi Dynamics Ax provide many other ways to communicate with databas...