Blog Archives

Cannot create a record, the record already exist

Most of the time during record creation, dynamics ax throws error.

Cannot create a record, the record already exists”

There could be multiple reasons for this issue. This post is targeted to resolve the issue #3

  1. Unique index is getting violated
  2. Number sequence used is not generating the correct number.
    • This may be the issue related to number sequence cache
      • This can be resolved setting the correct next number at the number sequence
  3. RecId is not getting the correct sequence
    1. This issue happens because of table synchronization issue during production build creation.

 

Solution Issue#3:

The way RecId number sequence generation works is that there is stored procedure namely ‘sp_GetNextRecId’ used by AX to generate next recId. AX does not call this stored procedure for each recId generation. It caches the range and when range expire, it call the SP to get the next ID.

There is also a table namly ‘SystemSequences’ where AX stores RecId along with table Id. if there any synchronization issue related to ID conflicts or new data is brought in, some times this sequences goes out of sync.

To correct the issue, We can update the table directly but we also have to flush cache for AX to starting looking at the change.

Code to update table and flush Cache

The code below is copied from Shashi’s blog. This solves the issue

static void SetNextRecId(Args _args)
{
SystemSequences seq;
ttsBegin;
select firstonly forupdate crosscompany seq
where seq.tabId == 123456; // use the table id here or tablenum()
seq.skipTTSCheck(true);
seq.skipDatabaseLog(true);
seq.selectForUpdate(true);
seq.nextVal = 5637123456 + 1; // enter the last recId for the table
seq.update();
ttsCommit;
}

You may need to run this job and restart the AX client only if the just the above doesn’t work

static void sab_recIdSequenceFix(Args _args)
{
SystemSequence systemSequence = new systemSequence();
Tableid tableId = 123456; // use the table id or tablenum() here

systemSequence.suspendRecIds(tableId);
systemSequence.suspendTransIds(tableId);
systemSequence.flushValues(tableId);
systemSequence.removeRecIdSuspension(tableId);
systemSequence.removeTransIdSuspension(tableId);
}

 

How to resolve deadlock issues in multithreading batch

Last week I solved an issue with the deadlock with a table and thought it is worth sharing the information as we are using multi-threading batches a lot.

 

Background about the issue:

In the batch, we are updating a log table to keep track of the messages sent outside using update_recordset. We are using where clause on two fields. In multi-threaded batch, deadlock was happening for all the records even though the multiple threads were working on different records.

Solution:

This took me a while but at the end what I found was if there is no index at the table for the where clause you are using in your query then sql locks the table at the time of update and not just a record. It uses table scan operator in the execution plan, hence causing the deadlock.

The reason why the developer did not put index at the table was there was no unique index in the table. So key lesson here is, create index even though it is not unique for the where clauses.

Below link provides really good information on how SQL deals with indexes

https://www.sqlpassion.at/archive/2014/11/24/deadlocks-caused-by-missing-indexes-in-sql-server/

How to get company fiscal calendar

 

Ledger::FiscalCalendar()

How to get current company in Axapta 2009 and 2012

Ax 2009

CompanyInfo::find();

Ax2012

As you know, in ax2012 there is concept of legal entity in place of company. Legal Entity can be retrieved as follows

CompanyInfo::Current()

How to make Vertical splitter on Forms in AX 2012

I was just making a vertical splitter, I thought I should share the steps here, it can be helpful to someone.

What is vertical splitter?

Vertical splitter is the separator that is aligned vertically on the Ax Form and it separates two section on the Form. Use can also stretch or expand the section by dragging this splitter. You can find the snap shot below

What are steps to achieve this functionality?

1. Make a group sections as follows and make a separate group for vertical splitter as below .

2. Set the style property of the Group container to as follows. Make the AutoDeclaration to Yes also.

3. Go to the Form class declaration and declare the variable that will hold the object of vertical splitter

 

SysFormSplitter_X VerticalSplitter;

4. Go to the Form init method and initialize the object as below

VerticalSplitter = new SysFormSplitter_X(VSplitter, Container, element);

5. Tuddddddddannnnnnnnnn !!!!!, you vertical splitter is ready

How can i change the order of control? Any short key?

I thought I should share a very useful trick for reordering the controls, relationships, fields and AOT. Sometimes it becomes head ache arranges controls or index on the Form and table. This post might be helpful for ne chaps. I think most of the experienced Ax professional know about this.

For reordering you can use ALT + arrow key.

Some more short keys
To restore AOT window CTRL + R
To close AOT window CTRL + F4

Dynamics Ax videos

A very good link for dynamics ax development video training

http://www.vimeo.com/tag:dynamicsax

What does client and server keywords do

What does server and client keywords do?

Many of the new x++ developers, when they start coding in x++ they really find hard to understand the usage of “Server” and “Client” keyword or server and client properties, Like when they should use the server method or the class and when the client keyword come into play. So I thought I should compose a post on this.

There are many books which throws light on this keyword, however they are more theoretical than practical and I think for a developer it is really necessary they are taught by live example by scenario so through the post below, I will try to be less theoretical and will try to be more practical and conceptual. Through my overall experience, I found that there are two ways to learn things

1. Fall and get stuck into the problem and try everything before you go through the book or search net (that who else fall into this problem and how he resolved it) and then use that solution. When you do that, you will understand the thinking behind the invention of the technique. You will get more clearer concept and you will have the Eagle’s eye view of the problems

2. Go through the book, copy paste the example and learn. But in this technique, it is hard to recall when you actually get into the problem.

Anyways let’s move to server client approach, I will try to keep it short and will post an example.

Ok so what does server keyword do?

Consider a scenario, where you as a developer or a technical consultant given a job to copy some files to the server through when someone setups something.

For instance, take an example of interest code in Account Receivable –> Collections –> Interest code. The scenario is, On the setting of interest code, you are setting something in file system, specific to the interest code and those file system settings will be used later by the interest calculation job for some calculation. Now, the requirement is there will be other web service that will be consuming those file settings.

What does the above scenario mean?

It means you need to do some setting in the code to copy the file system setting on the server as well. Now you if you see from top view, you need to do two things

1. Create Files on the client (Use the client class or client method for it)

2. Create files on the server because copy is not allowed between client and server normally.(Use the server keyword or server class for it)

How can I make server and client methods?

It is easy just put the server or client keyword before the method or class name and method should be static for Server. Client does not have this limitation.

We also have keyword Server Client for the method and class, what does it mean?

The server client method works as the Called from property of the AOT Object, which means the object execution will be dependent on the caller. If the client method or class is calling the server client class, the class or method will be executed on the client machine and vice versa.

How to test that my server and client methods are working fine?

You can check by setting or getting the value of APPData environment variable as follows

And you can also play with more scenarios by calling the class or method from the client or server caller and check in the result.

Can only classes consume these keywords?

1. No, I think for tables, class can use these keyword through code

2. Forms cannot run a server method because it always runs on client

3. We can also set the properties through AOT properties form, so there is no limitation of classes and tables.

I hope this post help you guys. Please forward me your queries through comments below.

Ways to debug query and relationship related issues in AX5 forms

Problem statement

I open a child form and it is not showing any data. How should I debug this?

Solution

These type of issues are mostly related with the query or with the relationships between the child and parent Table or Form records. I would like to add some point here, that may help in troubleshooting these sort of issues

1) Check the form query, you can do it this From Form –> setup –> Query tab
2)Check out the init(…) method, does it contain the args(…) setting, is it setting the query here.

Once you are able to figure out that it is the query issue, you can check the following steps

1) Check out the relations on the table
2)Check out the code in init(…) and the execute Query (…) method. Check for the query related code.

How to get system date and session date in Ax

How to get session date time using preferred time zone in x ++

DateTimeUtil::date(DateTimeUtil::applyTimeZoneOffset(

DateTimeUtil::getSystemDateTime(), DateTimeUtil::getUserPreferredTimeZone())))

How to get system date in x++

systemDateGet();