Skip to main content

Notifications

Finance | Project Operations, Human Resources, ...
Unanswered

Invalid Relation between entities

(0) ShareShare
ReportReport
Posted on by 465

I'm getting this error when exporting the composite  entity: "Invalid relation between entities"  

The relation between Entity2 and Entity1 is:
Entity1.Id = Entity2.Id

Entity1.JournalParmId= Entity2.JournalParmId

Entity1.LinkedJournalId = Entity2.JournalId

image

Entity1 EntityKey: JournalId

Entity2 EntityKey: JournalId


LinkedJouranId
 and LinkedJournalType are computed columns:

public static server str LinkedJournalId()
{

        return  strFmt('ISNULL((select top 1 JournalId from Table1 as table1 WHERE table1.PARTITION = %1 AND table1.DATAAREAID = %2 AND table1.JournalParmId = %3 AND table1.JournalId != %4 AND table1.Id = %5 AND table1.JournalType != %6), %7)'
            , SysComputedColumn::comparisonField(tableStr(Table1View), identifierStr(Table1), fieldStr(Table1, Partition))
            , SysComputedColumn::comparisonField(tableStr(Table1View), identifierStr(Table1), fieldStr(Table1, DataAreaId))
            , SysComputedColumn::comparisonField(tableStr(Table1View), identifierStr(Table1), fieldStr(Table1, JournalParmId))
            , SysComputedColumn::comparisonField(tableStr(Table1View), identifierStr(Table1), fieldStr(Table1, JournalId))
            , SysComputedColumn::comparisonField(tableStr(Table1View), identifierStr(Table1), fieldStr(Table1, Id))
            , SysComputedColumn::comparisonField(tableStr(Table1View), identifierStr(Table1), fieldStr(Table1, JournalType))  // this is new
            , SysComputedColumn::comparisonLiteral('')
             );
    
}


public static server str LinkedJournalType()
    {

        return  strFmt('select top 1 JournalType from Table1 as table1 WHERE table1.PARTITION = %1 AND table1.DATAAREAID = %2 AND table1.JournalParmId = %3 AND table1.JournalId != %4 AND table1.RentId = %5 AND table1.JournalType != %6'
            , SysComputedColumn::comparisonField(tableStr(Table1View), identifierStr(Table1), fieldStr(Table1, Partition))
            , SysComputedColumn::comparisonField(tableStr(Table1View), identifierStr(Table1), fieldStr(Table1, DataAreaId))
            , SysComputedColumn::comparisonField(tableStr(Table1View), identifierStr(Table1), fieldStr(Table1, JournalParmId))
            , SysComputedColumn::comparisonField(tableStr(Table1View), identifierStr(Table1), fieldStr(Table1, JournalId))
            , SysComputedColumn::comparisonField(tableStr(Table1View), identifierStr(Table1), fieldStr(Table1, Id))
            , SysComputedColumn::comparisonField(tableStr(Table1View), identifierStr(Table1), fieldStr(Table1, JournalType))
             );
}


*I've noticed that if JournalParmId in Entity 1 is not repeated then the export doesn't fail like example below 

pastedimage1675606544194v1.png




-- however, if more than JournalParmId in entity1, then it fails

  • D365FO user Profile Picture
    D365FO user 465 on at
    RE: Invalid Relation between entities

    Hi Martin,

    I tried to do the entity in a different way without using computed column in relation:  -- still same issue

    I created a new link

    |community.dynamics.com/.../error-when-exporting-the-entity-invalid-relation-between-entities

  • D365FO user Profile Picture
    D365FO user 465 on at
    RE: Invalid Relation between entities

    JournalParmId is when you create two Journals in the same button click.

    So for example if you want to replace an item with another item, you click one button to do the replacements, where two journals gets created with the same JournalParmId and from a business point of view these two are linked --- this is an example of J2 and J3

    And in the new case for (J4, J5 and J6) -- you can click a button to collect three items but they have a different address, so three journals gets created for each item with the same JournalParmId -- but those are not considered linked that's why i don't want them to appear in the linked entity (child)

    However, if you collect three items that have the same address, only one journal will get created that contains these three items

  • Martin Dráb Profile Picture
    Martin Dráb 230,836 Most Valuable Professional on at
    RE: Invalid Relation between entities

    Sorry, but your data models no sense to me. For example, I got no information about the meaning of JournalParmId. I can't help you.

    All I can say is that the design of your entities looks extremely weird, but I don't have enough to either understand it or to propose something more meaningful.

  • D365FO user Profile Picture
    D365FO user 465 on at
    RE: Invalid Relation between entities

    but those are different entities that are joined together in a composite entity. So if Entity1 (parent) which consists of table1 had J1, then Entity2 which consists of table1 as well can have J1 as well, as the entity key is JournalId for each one.

    So table1 can have J1 and J1 can't be repeated true. But Entity1(Parent) can have J1 and Entity2(Child) can have J1

    But anyways what I'm trying to do is Make Entity1 contain Journals that shouldn't appear in Entity2. That's why i made the link between them based on Entity1.LinkedJournalId = Entity2.JournalId

    So i'm assuming if I join the two entities here based on ID JounralParmId and LinkedJournalId

    pastedimage1675681656607v1.png


    The result should be like this  -- when joining the two entities based on the relation i specified   -- but i'm not sure why the entity is failing

    Id  JournalId  JournalParmId  JournalType  LinkedJournalId   LinkedJournalType   Id   JournalId  JournalParmId  JournalType     
    1     J1           1A             10                             NULL            NULL   NULL       NULL           NULL
    1     J3           2B             0             J2               15              1      J2          2B            15
    1     J4           4C             15                             NULL            NULL   NULL       NULL           NULL
    1     J5           4C             15                             NULL            NULL   NULL       NULL           NULL
    1     J6           4C             15                             NULL            NULL   NULL       NULL           NULL

  • Martin Dráb Profile Picture
    Martin Dráb 230,836 Most Valuable Professional on at
    RE: Invalid Relation between entities

    Yes, I know it's the table table - I'm talking about records in the table. When you say that JournalId in Table1 is unique and you have two records - a parent and a child - they must have two different Journal ID. If they had the same, JournalId wouldn't be unique.

  • D365FO user Profile Picture
    D365FO user 465 on at
    RE: Invalid Relation between entities

    Hey Martin,

    But Parent and Child are exactly the same table which is table1

    So table1 in general has J1,J2,J3,J4,J5,J6  

    -- J2 and J3 are linked and share the same JournalParmId

    -- J4,J5,J6  are not linked from a business point of view but they still share the same journalParmId

    So Parent Entity (which is table1 joined with another table) has J1,J3,J4,J5,J6 -- no J2

    And I designed child entity in a way to show linked Journals from table1

    so that the xml shows

    J1 in Parent linked with nothing from child

    J3 in Parent linked with j2 from child

    J4 in Parent linked with nothing from child

    J5 in Parent linked with nothing from child

    J6 in Parent linked with nothing from child

    So when i say child entity shouldn't show journals from ParentEntity.. is because child node should only show J2 in this case

    that's why i made this link childEntity.JournalId = ParentEntity.LinkedJournalId

    and they way i detected linkedJournalId in ParentEntity, is by looking at a journal  who has the same JournalParmId but different JournalId -- So again J2 and J3 has same JournalParmId but because Parent has J2 i only want to get J3

  • Martin Dráb Profile Picture
    Martin Dráb 230,836 Most Valuable Professional on at
    RE: Invalid Relation between entities

    If Journal ID in the table is unique, two record (a parent and a child) clearly can't have the same Journal ID, because that wouldn't be unique.

  • D365FO user Profile Picture
    D365FO user 465 on at
    RE: Invalid Relation between entities

    Hi Martin,

    Yes i need to check if JournalId is not equal to the parent. because Table1Entity and LinkedTable1Entity have the same table, so the inner node related to LinkedTable1Entity, should not show the same JournalId in the parent. And in the new case it should not show the same JournalId in the parent AND it should not show same JournalType as the parent

    So currently here's the case that is breaking the entity as I mentioned before

    Table1Entity  // note that here there is no J2, because always when 2 records are actually linked, only 1 appears that i detect by joining table1 with another table

    Id  JournalId  JournalParmId  JournalType  LinkedJournalId   LinkedJournalType
    1     J1           1A             10                             NULL
    1     J3           2B             0             J2               15
    1     J4           4C             15                             NULL
    1     J5           4C             15                             NULL
    1     J6           4C             15                             NULL



    LinkedTable1Entity  // contains table1 not joined with anything so J2 appears here, but because it's not in Parent entity I make sure it will only appear in inner node and not parent node.
    Id  JournalId  JournalParmId  JournalType
    1     J1           1A             10                            
    1     J2           2B             15
    1     J3           2B             0                           
    1     J4           4C             15                             
    1     J5           4C             15                            
    1     J6           4C             15                            


    now when joining these two entities  -- relation based on ID, JournalParmId and LinkedTable1Entity.JournalId = Table1Entity.LinkedJournalId

    When I'm standing at J1,  Linked node should show nothing

    When I'm standing at J3, Linked node should show J2

    When I'm standing at J4, Linked node should show nothing

    When I'm standing at J5, Linked node should show nothing

    When I'm standing at J6, Linked node should show nothing

    ** my previous comment that contains the xml shows all the details as well

    goshoom  when I had J1,J2 and J3 in table1, the entity didn't break, because when J2 and J3 where linked, EntityTable1 didn't contain both J2 and J3, just J3.

    But now since there is J4.J5,J6 and they both appear in both entities by sharing the same journalParmId, but they are not actually linked,it fails.
    So somehow it's failing when the JournalParmId is repeated in Parent Entity. but why??

  • Martin Dráb Profile Picture
    Martin Dráb 230,836 Most Valuable Professional on at
    RE: Invalid Relation between entities

    If Journal ID is unique, involving the other fields is useless, because they can't make it any more unique.

    Also, you don't need to do anything to make sure that "its JournalId is not equal to JournalId of the parent". If Journal ID is unique, a record can't have the Journal ID same as any other journal, including the parent.

  • D365FO user Profile Picture
    D365FO user 465 on at
    RE: Invalid Relation between entities

    Hi Martin,

    No JournalId alone is unique -- and the primary key of the table is JournalId

    ID is there just to be more sure  -- ID is like the order number

    so you can say as well: inner node needs to display all records that have the same ID and same JournalParmId as the parent but it's JournalId is not equal to JournalId of the parent.

    goshoom  but after the new case inner node needs to display all records that have the same ID and same JournalParmId as the parent but it's JournalId is not equal to JournalId of the parent and it's JournalType is not equal to JournalType of the parent

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

Announcing Our 2025 Season 1 Super Users!

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

Announcing Forum Attachment Improvements!

We're excited to announce that attachments for replies in forums and improved…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,965 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 230,836 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans