Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

Init value for data entity primary index field?

(0) ShareShare
ReportReport
Posted on by 11

Hello!

I'm trying to create data entity for table which primary index is PersonId, accordingly data entity and staging table primary index contains PersonId

pastedimage1638905230533v2.png

pastedimage1638905282979v4.png

My question: is it possible to fill PersonId from number sequence if the field in excel(or other type of DS) is empty, if not the use the value from file. Is it even possible.

I tried to use initValue() 

pastedimage1638905990844v5.png

tried  insertEntityDataSource(), mapEntityToDataSource() (not present, already deleted them), but nothing works, it doesn't even hit those methods, because it don't get past staging table. Getting the error: data violates integrity contstraints.

Do I need to make some changes to staging table too? I'm really stuck, can't figure it out. Don't know if it even possible.

Can you please suggest me something, point me in right direction.

Kind Regards,

Maris

  • Maris Sausins Profile Picture
    11 on at
    RE: Init value for data entity primary index field?

    Thank you André and Martin for your valuable time!

    Will try the 2 approach with different primary key too!

  • Maris Sausins Profile Picture
    11 on at
    RE: Init value for data entity primary index field?

    I tried your suggested approach and added check in mapEntityToDataSource() if personId fomat matches number sequence format, if not then assign new value from number sequence:

    pastedimage1638987880448v1.png

    Seems like everything is working. Only thing is that, still getting error msg in log for ID's which don't match number sequence format.

    Maybe someone else will find it useful!

    Kind regards,

    Maris

  • Verified answer
    Martin Dráb Profile Picture
    231,893 Most Valuable Professional on at
    RE: Init value for data entity primary index field?

    You have two options - either you do it when moving data to target, and then mapEntityToDataSource() is one of the options. Or you can do it immediately after putting records to the staging table (in postGetStagingData()). I would choose the former approach in this case.

    Regarding the check of the number sequence pattern, I think that's what NumberSeqRecordFieldHandler does in handleValidatingField(). It calls NumberSeq::checkChangeNumber() to the actual job.

    Re 2) Yes, I think so.

  • Maris Sausins Profile Picture
    11 on at
    RE: Init value for data entity primary index field?

    Hi, Martin! Thanks for your response!

    1) If I use dummy person ID, what would be the best method to update it? mapEntityToDataSource?

    Is there a way to get currently used number sequences pattern, so I can compare it to field value from source, if they don't match, then assign value from number sequence.

    2) If I use different primary key, then I would be able to achieve the goal with the initValue() method (screenshot above). That's correct?

    Kind regards,

    Maris

  • Martin Dráb Profile Picture
    231,893 Most Valuable Professional on at
    RE: Init value for data entity primary index field?

    Making it non-mandatory allows you to save a record without PersonId, but you still can't save two records without PersonId. It violates the primary index (both records have the same DefinitonGroup, ExecutionId and PersonId).

    You'll either need to use a different primary key, or you'll need to provide dummy unique person IDs (that you'll then update in code).

  • Maris Sausins Profile Picture
    11 on at
    RE: Init value for data entity primary index field?

    Hi, André! Thanks for your fast response.

    I have already tried to make those non-mandatory, but it still doesn't work.

    I looked at the the example you suggested, the initValue() and initializeEntityDataSource() methods are basically the same as I have. I think other methods are not relevant to me in this case, or maybe I'm mistaken.

    I exported data with the entity, to get the template, then added 2 new records with empty PersonId field and tried to import it, but got error:

    "Failed to insert record into staging table. The keys of the record are DEFINITIONGROUP, EXECUTIONID, PARTITION, PERSONID. Duplicate records must be removed from the file prior to import.-The duplicate key value is (5637144576, PrmPersonsImport, PrmPersonsImport-2021-12-08T00:16:22-1884AF58559D4B478245696A2D64681D, )

    '0' 'Persons' record(s) inserted in staging"

    PersonId field is set to Non-Mandatory.

    Whats I'm doing wrong?

    Kind regards,

    Maris

  • Verified answer
    André Arnaud de Calavon Profile Picture
    293,112 Super User 2025 Season 1 on at
    RE: Init value for data entity primary index field?

    Hi Maris,

    On the data entity and the staging table, you have to ensure the PersonId is not mandatory. The error you get now, indicates that there is an invalid value. This can be caused by the mandatory setting.

    You can look at e.g. the data entity EcoResReleasedProductCreationV2 as example

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 293,112 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,893 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156 Moderator

Leaderboard

Product updates

Dynamics 365 release plans