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
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
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.
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?
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.
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,
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.