web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Dynamics 365 Community / Forums / Finance forum / Linenum in custom enti...
Finance forum

Linenum in custom entity D365 x++

(0) ShareShare
ReportReport
Posted on by

Hi expert

1. I have created a custom entity  and i have added a field called linenum(extends tradelinenum) . I want this field to incremented each time a new record is imported.  How can I achieve it. 

Some facts about my data entity

1. It's a set based entity. I have overridden copystaging to target method 

2. I can set the auto increment property on linenum . Reason linenum is a part of the index on entity and staging table and linenum is set as noneditable and mandatory. Noneditable fields can't be set as autogenerated in the entity mapping.

3. I tried to override the insert method on the staging table but it dint work.

Please advise how can I achieve this.

Br

P

I have the same question (0)
  • Sukrut Parab Profile Picture
    71,710 Moderator on at

    What logic you wrote in copystatingtoTarget method ? Are you inserting data in table through insert_recordset statements ? 

  • Community Member Profile Picture
    on at

    Hi sukrut

    In postgetstagingdata method I am doing some data mapping like item I receive in file I update it with item in d365(update staging table) using insertrecordset and updaterecordset. In copyTargettostaging I am using while to loop through staging table and create some orders.  Why while loop in copytargettostaging ? Because I receive flat file(header and line in one row) and also I have to do some logic before I insert data in target .

  • Sukrut Parab Profile Picture
    71,710 Moderator on at

    Writing while loop with in copytargettostaging  method does not make sense because you are  not doing set based operation. Anyways you said this is custom entity then what if you make this field editable and set autogenerated ? Did you try that ?

  • Pete Alberts Profile Picture
    3,542 on at

    So the field is non-editable and mandatory on table? A quick work around will be to change mandatory to "no".

    Then I do not think what you are trying to achieve is possible with a Data Entity that supports set-based sql operations.

    I haven't overridden methods on the staging table - I am quite sure that logic is meant to be on the Data Entity.

    I can assist with exactly where you need to place the LineNum generation code - but first please confirm the Allow Edit, Allow Edit on Create and Mandatory properties on the table as well as the Data Entity.

  • Community Member Profile Picture
    on at

    Hi allowwdit and allowedit on create are set as yes on staging and on dataentity its auto

  • Community Member Profile Picture
    on at

    Yes I tried and it works and I am aware of it. However i am finding ways to generate linenum via code.

  • Suggested answer
    Pete Alberts Profile Picture
    3,542 on at

    Firstly - forget about the staging table. Don't edit anything there. You should only update the staging table from the data entity (that option when you right click on the data entity top node).

    You did not mention the properties on the actual table. I assume it is AllowEdit-No, AllowEditOnCreate-Yes and Mandatory-Yes.

    Then do the following:

    1. On the mapped field in the data entity - leave everything standard, except set Mandatory to No.
    2. Then write your code pre-super() in insertEntityDataSource().
    3. The code should be something like this:

    Screenshot-2019_2D00_08_2D00_27-at-09.05.44.png

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

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Coming on 11/8!

In our never-ending quest to help the Dynamics 365 Community members get answers faster …

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard > Finance

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans