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 :
Microsoft Dynamics 365 | Integration, Dataverse...
Answered

Condition in FetchXML for Link-Entity

(0) ShareShare
ReportReport
Posted on by 905

Hello,

I have a table called job position that has Parent Job position (Lookup to the same table Job position) and Job Position as Single line text field.

What I want to achieve through fetch XML is the below:


When I filter a Job position that has the Parent Job position blank or null (which means it is the parent) I don't want the query to rely on the link-entity. Because the link-entity purpose is that if Job position has a parent job position that means not null and it is not the parent it should return as a result the Parent job position name of the Job position that I am filtering on.

pastedimage1659902217786v1.pngpastedimage1659902277421v2.png
I tried the below fetchXML query:





















The above query returns nothing knowing that the above IT manager position is the parent position and the field is null.

I believe this is because the link-entity is getting executed and found that the parent is null so the logic that should be applied is to not execute the link entity if the parent job is null.

What should be the updated query for this scenario? Could you please provide an example?

Any help is highly appreciated.

Best regards,
EBMRay

I have the same question (0)
  • Guido Preite Profile Picture
    54,086 Moderator on at
    RE: Condition in FetchXML for Link-Entity

    I read your question 3 times but I probably still don't understand exactly your requirements.

    If I understood correctly you have a self-table relationship (because in dataverse you can't create 1-1 relationships you have 1-n, meaning you have 1 parent at the top, n children, each child can be a parent to other n children).

    this condition here

    <condition attribute="cr884_parent_job_position" operator="null" />

    will retrieve only the top parent records, I think you should add the outer clause to the link entity, as the default is inner, something like

    <link-entity name="cr884_job_position" from="cr884_job_positionid" to="cr884_parent_job_position" link-type="outer">

    you can find fetchxml relationships details here if you are interested markcarrington.dev/.../

    however because you already set the condition as null the link entity is completely useless, maybe you can use two queries in order to fetch the data?

    hope it helps

  • Suggested answer
    Leco Lv Profile Picture
    on at
    RE: Condition in FetchXML for Link-Entity

    Hi   EBMRay,

             I think there may be two problems with your code.

    1. Your  GUID value may be wrong, please check it.
    2. from="cr884_job_positionid" to="cr884_parent_job_position" are written backwards.

    Here  is my modified code:

    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
     

  • EBMRay Profile Picture
    905 on at
    RE: Condition in FetchXML for Link-Entity

    Hello Guido Preite ,

    Sorry for not being clear in my requirements.

    Yes, the parent job position is a lookup on the same table itself since we cannot create 1:1 relationship.

    I added the below condition to try in a way to not execute the link entity if the parent job position is null but I failed in that.

    <condition attribute="cr884_parent_job_position" operator="null" />

    In case the parent position was not blank the link entity should be used in order to get the responsible person of this position that's the reason why I am using the link entity in the same query. However, if the parent position was blank that means the position itself is the Head (parent).

    I tried to add the link-type outer for the link entity:

      
        
        
        
        
        
          
          
        
        
          
          
          
          
            
            
            
          
        
      
    


    Unfortunately, the query did not return any data as result based on the changes we applied.

    Could you please advise what might be the issue?

    Thank you!

  • EBMRay Profile Picture
    905 on at
    RE: Condition in FetchXML for Link-Entity

    Hello Leco Lv ,

    The GUID number is right and below are some screenshots:

    Screenshot-3.png3632.Screenshot1.png

    I tried the modified query that you provided and it worked only if the parent job position is null, however, if I changed the guid to a record that has a parent job position meaning not null the query returns nothing.

    As a result, based on the above scenario, It should return the responsible employee of this position from the same table itself.

    What should be the updated query to solve this issue?

    Awaiting your response.

    Best regards,
    EBMRay

  • Suggested answer
    Community Member Profile Picture
    on at
    RE: Condition in FetchXML for Link-Entity

    Hi  EBMRay ,

          Do you mean that the result can be returned regardless of whether the position is null or not.

          If so , just delete the ninth line : <condition attribute="cr884_parent_job_position" operator="null" />

      
        
        
        
        
        
          
          
        
        
          
          
          
          
            
            
            
          
        
      
    

    Regards,

    Leco Lv1

    Please mark as verified if the answer is helpful. Welcome to join hot discussions in Dynamics 365 Forums.

  • EBMRay Profile Picture
    905 on at
    RE: Condition in FetchXML for Link-Entity

    Hello  ,

    Thank you for providing the below query.

    I already removed the ninth line and executed the query again on a record that has a parent job position assigned and it returned 0 records as a result:

      
        
        
        
        
        
          
        
        
          
          
          
          
            
            
            
          
        
      
    

    The record that I triggered my query on is mentioned in a screenshot above previous replies.

    Please let me know why it does not work and what we still need to change.

    Awaiting your response.

    Best regards,
    EBMRay

  • EBMRay Profile Picture
    905 on at
    RE: Condition in FetchXML for Link-Entity

    Hello Leco Lv     ,

    I would highly appreciate your response based on my last reply.

    Best regards,
    EBMRay

  • EBMRay Profile Picture
    905 on at
    RE: Condition in FetchXML for Link-Entity

    Hello  ,

    I would highly appreciate your support on this case.

    Best regards,

    EBMRay

  • EBMRay Profile Picture
    905 on at
    RE: Condition in FetchXML for Link-Entity

    Hello  ,

    Could you please assist me with this issue?

    Thank you!

  • Verified answer
    Leco Lv Profile Picture
    on at
    RE: Condition in FetchXML for Link-Entity

    Hi  EBMRay,

         I'm sorry it took so long to reply to you, I missed your Notifications.

         I'm not quite sure why your code isn't working, and I double-checked your code and found no problems. I executed it myself and successfully queried the results.

         The screenshot below contains my table relationship and the result of successful execution.

          BAD&erere(child)

          pastedimage1660877995835v1.png

         pastedimage1660878040008v3.png

         Results:

         pastedimage1660878059658v4.png 

         Here's the code I executed:

      
        
        
        
        
        
          
        
    	
          
          
    	  
            
          
        
      
    
    
    

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…

Pallavi Phade – Community Spotlight

We are honored to recognize Pallavi Phade as our Community Spotlight honoree for…

Leaderboard > Microsoft Dynamics 365 | Integration, Dataverse, and general topics

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 54 Most Valuable Professional

#3
Tom_Gioielli Profile Picture

Tom_Gioielli 45 Super User 2025 Season 2

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans