Question Status

Suggested Answer
ChrisAX asked a question on 25 Mar 2014 6:40 AM

Hi

I have to create customers by code. Everything works fine, except the assignment of the MainContactWorker.

I do have the personnelnumber of the responsible worker. I call HcmWorker::findByPersonnelNumber(myWorkerNum) and assign the RecId.

The find-method works perfect, I get the correct data and the correct recid, but after I assigned it the Recid is completely different

Example

custTable.MainContactWorker = HcmWorker::findByPersonnelNumer("000002").RecId;

The find method returns Recid 5637144577 but the field MainContactWorker has 1372459874

What I recognized is that I do have dataareid 'DAT' in the find method, but I should be in 'IDI'

The Workers are shown in both companies

Reply
Suggested Answer
André Arnaud de Calavon responded on 25 Mar 2014 9:40 AM

Hi Chris,

This is very strange. The find method should return only one and the correct record id for the worker. The dataarea ID is 'DAT' because this table is globally shared in AX. So all workers can be seen in any company.

Can you check if you have record in this table where this personnel number has a duplicate? Out of the box it should not be possible as there is an index on this field not allowing duplicates.

kind regards,

André Arnaud de Calavon  |  Microsoft Dynamics AX Solution architect  |  My blog  |  My company

This post is my own opinion and does not necessarily reflect the opinion or view of my company, Microsoft, both its employees, or other MVPs.

Reply
Suggested Answer
André Arnaud de Calavon responded on 25 Mar 2014 9:40 AM

Hi Chris,

This is very strange. The find method should return only one and the correct record id for the worker. The dataarea ID is 'DAT' because this table is globally shared in AX. So all workers can be seen in any company.

Can you check if you have record in this table where this personnel number has a duplicate? Out of the box it should not be possible as there is an index on this field not allowing duplicates.

kind regards,

André Arnaud de Calavon  |  Microsoft Dynamics AX Solution architect  |  My blog  |  My company

This post is my own opinion and does not necessarily reflect the opinion or view of my company, Microsoft, both its employees, or other MVPs.

Reply
Gertjan van der Linden responded on 26 Mar 2014 2:18 PM

Is the value returned from the find method incorrect or is the value initially filled correctly and might it be overwritten in a method that is called later on? You indicate that the find method returns the correct value. That value should be assigned to the mainContactWorker but there might be some code overwriting this value later on?

Can you check on this?

Greetings, Gertjan van der Linden | Dynamics AX Solution Architect

Reply
Eyvindur Tryggvason responded on 26 Mar 2014 4:32 PM

I would try debugging and see if the assignment is ok and if it possibly changes after insert.  The initValue e.g. initializes this field and the validateWrite and validateField do some checking on it.  Might be that  methods in the insert method change the value.

Reply
ChrisAX responded on 26 Mar 2014 10:01 PM

Hi

I am so sorry, I found my error. Because I Import the customers from an Excel I assigned all my values into variables in an init-Method, there I took the wrong variable by mistake,

BR

Chris

Reply
André Arnaud de Calavon responded on 27 Mar 2014 1:28 AM

Hi Chris,

Thanks for the feedback. Can you verify one or more answers which really helped you? You can actually also mark your own answer. Then this thread is marked as answered.

kind regards,

André Arnaud de Calavon  |  Microsoft Dynamics AX Solution architect  |  My blog  |  My company

This post is my own opinion and does not necessarily reflect the opinion or view of my company, Microsoft, both its employees, or other MVPs.

Reply