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

Community site session details

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

adding a new table to an existing data entity

(0) ShareShare
ReportReport
Posted on by 465

I created a new table, that has InvoiceId, InvoiceDate, LedgerVoucher, SalesId, NumberSequenceGroup and a Boolean flag. I put a relation on the table with custInvoiceJour with the  all fields i just mentioned except of the flag.

I inserted in this table one record with valid data based on the custInvoicJour.

Now i went to SalesInvoiceHeaderV2Entity and added this new table under custinvoicejour node datasources , I made the relation inner join with custInvoiceJour and added a relation based on InvoiceId,InvoiceDate and ledgerVoucher. Also i added range where boolean flag = false.

I made a composite entity with SalesInvoiceHeaderV2Entity and SalesInvoiceLineV2Entity that was working fine before i added this new table. Now when i added the table when i export it, i get succeeded but with 0 data and it says that child entities has failed status. 

Why is that?

I have the same question (0)
  • Sergei Minozhenko Profile Picture
    23,093 on at
    RE: adding a new table to an existing data entity

    Hi D365FO_User,

    It's not a good idea to break a standard entity with such kind of change. It's better to use an outer join and add range in a data project.

    Do you have any duplicates in your new table? Do you see any error in the data project? Have you checked the event viewer log for errors?

  • D365FO user Profile Picture
    465 on at
    RE: adding a new table to an existing data entity

    But how would an outer join solve it for me, i only want to see the invoices in the new table where the flag is not ticked when i export the project

    No duplicates, this table is filled when a sales order gets invoiced but i made the same index as custInvoiceJour

    this is what i get:
    pastedimage1592290218853v1.png

  • Sergei Minozhenko Profile Picture
    23,093 on at
    RE: adding a new table to an existing data entity

    Hi D365FO_user,

    Using InnerJoin for a custom table in the standard entity, you completely change the behavior of the entity. For example, if you decide to export sales invoices to BYOD later, you will not be able to use this entity, because it's now supposed to be used only for a particular case.

    Have you tried to check if header export only works (not in the composite entity)? There is a button "View execution log" on execution summary form, do you see any additional information there? Have you checked Windows event viewer for additional information?

    What kind of index you have created, is it unique?

  • D365FO user Profile Picture
    465 on at
    RE: adding a new table to an existing data entity

    So i should make a copy of the header entity and use this new one instead of the standard one in my composite.

    I tried the header only, i get succeeded with 0 records exported.

    when i tired the composite, i got succeeded also with 0 records exported, no errors. But i'll check now the even viewer but last time i didn't get any additional info from it.

    Here's my table, the index is allow duplicate no and the relation, cardinality ZeroMore and relatedCardinality ExactlyOne
    pastedimage1592294254268v1.png

    and in the header entity

    pastedimage1592294462338v2.png

  • D365FO user Profile Picture
    465 on at
    RE: adding a new table to an existing data entity

    i knew what the issue is, in the range for the flag field i put the value false in AOT, i replaced it with 0 and i started getting data. I created a new data entity for the header as u suggested.

    1.Are my relations correct in the previous picture correct?

    2. i got this error when i duplicated the entity and staging : BP Rule: DataEntitySecurityPrivilegeCheck, so i checked the standard header entity privileges and only made a new one similar to the one highlighted in yellow and i only put in the data permission my new data entity without the others. and the error disappeared but i just want to make sure if i might need other privileges for the future or is this enough?
    pastedimage1592301251821v1.png

    3. i told u that i'm currently filling this table when a sales order is invoiced, to do this i made an extension of method created payment in SalesFormLetter_Invoice.... but right now it will loop twice in the standard method and in my extension, is there another way?

    [ExtensionOf(classStr(SalesFormLetter_Invoice)) ]
    public final class AASalesFormLetter_InvoiceAA_Extension
    {
        protected void createPayment()
        {
            next createPayment();
    
            Set journalSet = Set::create(formletterOutputContract.parmAllJournalsPacked());
            SetEnumerator se = journalSet.getEnumerator();
    
            while (se.moveNext())
            {
                CustInvoiceJour custInvoiceJour = se.current();
                AASalesInvoices salesInvoice;
                salesInvoice.InvoiceId = custInvoiceJour.InvoiceId;
                salesInvoice.InvoiceDate = custInvoiceJour.InvoiceDate;
                salesInvoice.SalesId = custInvoiceJour.SalesId;
                salesInvoice.LedgerVoucher = custInvoiceJour.LedgerVoucher;
                salesInvoice.numberSequenceGroup = custInvoiceJour.numberSequenceGroup;
                salesInvoice.insert();
            }
        }
    
    }

  • Sergei Minozhenko Profile Picture
    23,093 on at
    RE: adding a new table to an existing data entity

    Hi D365FO_User,

    1. Personally, I would make RefRecId field on my custom table and put RecId invoice record and use it as a relation. But I think the relation by fields you have already used is enough.

    2. It should be enough, don't forget to assign privilege to role or duty, otherwise, it makes no sense

    3. There is class SalesInvoiceJournalPost where all posting logic is stored and method endPost is usually used for additional actions after posting. If you decide to use it, you don't need to create any loops.

  • D365FO user Profile Picture
    465 on at
    RE: adding a new table to an existing data entity

    3. Thank you, yeah this is better.

    One more thing please, as you know i'm exporting this data project by code using a batch job. where i specify in the code the name of the export project of the composite entity.

    Now what if the user wants to exclude certain invoices that has the flag is set to false in my new table or what if the user wants to include some invoices that already has flag = true.

    so i want before i click on the batch, maybe have 2 parameters one for including invoices that has flag = true and another one to exclude invoices that has flag = false. If nothing is specified then it will take the ones with flag = false

    Is this doable? because u mentioned before that the range is applied only once then it will keep taking the first range done also is this doable with my inner join that i just made? can you please advise?

  • Sergei Minozhenko Profile Picture
    23,093 on at
    RE: adding a new table to an existing data entity

    Hi D365FO?user,

    If I remember correctly for composite entities you need to use template data project to get default query if you want to export data with class DMFEntityExporter, but you can modify the query based on your needs in x++ in your batch and create new create one-time data project for export itself.

    If you want to use your flag (i guess it's IsProcessed) in the query in x++ you need to add it as a field to the entity and remove range from the data source level and use the range on a data project level.

  • D365FO user Profile Picture
    465 on at
    RE: adding a new table to an existing data entity

    Here's how i do it:

    DMFDefinitionGroupName definitionGroupName = "Export";
    
            try
            {
                str x = "#FieldGroupName_AllFields";
    
                EntityName      entityName;
                DMFEntity       dmfEntity;
    
    
                select firstonly dmfEntity  order by EntityName asc where dmfEntity.TargetEntity == dataEntityViewStr(AASalesInvoiceV2Entity);
    
                entityName = dmfEntity.EntityName;
    
                Query                query = new Query(DMFUtil::getDefaultQueryForEntity(entityName, "Export"));
                // QueryBuildDataSource qbds = query.dataSourceTable(tableNum(SalesInvoiceHeaderV2Entity));
        
                //Apply needed ranges
    
    
                DMFEntityExporter exporter = new DMFEntityExporter();
                fileId = exporter.exportToFile(entityName,
                                    definitionGroupName,
                                    '', //Optional: ExecutionID
                                    "XML-Element", //Optional::SourceName
                                    x, //Optional field selection
                                    query.pack(), //Optional: Filtered Query
                                    curExt() //Optional: DataAReaId
                                    );

    1. By template data project u mean a project that already exists in AX?  and what is the difference between this project i specify here and the project name i put in exportTofile?

    2. As i mentioned this code is inside a batch.... so when i click on the menu item of the batch before i click send, the user should specify if he wants to exclude some of those who have flag = false or include some of those who have flag  = true. And based on his selection, i must take this into consideration in code when he clicks send and generate the file based on his selection. So this should be done on the batch dialog but how to do it?

  • Sergei Minozhenko Profile Picture
    23,093 on at
    RE: adding a new table to an existing data entity

    Hi D365FO_User,

    It's a little bit different topics, but

    1. Data project in getDefaultQueryForEntity is used to create default query (template project)

    Data project used in exportToFile is used for actual export and if the data project already exists, the query from the data project specified for exportToFile will be used, if it doesn't exist - new data project will be created with the query you provide

    2. Here you have different options, you can use SalesOrderHeaderV2Entity as a query for the dialog and ask the user to specify query filters and before exportToFile method call copy filters from query dialog to query for export. Or you can create dialog like for invoice posting where users can mark invoices to be sent, but in this case, you would need to think about the case when several users will do sent at the same time.

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
CA Neeraj Kumar Profile Picture

CA Neeraj Kumar 1,771

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 806 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 542 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans