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 :
Customer experience | Sales, Customer Insights,...
Suggested Answer

Help with xml cannot get the correct result...

(0) ShareShare
ReportReport
Posted on by 886

Hi,

I hope you can help me with this. I have the below relationships from customer asset to work order incident (Standard MS)

I also stated some values that should be used in the fetch. The value on the customer asset field cus1_parentassetid is only temporary to narrow results down.

I wan't only the customer asset to be shown if a linked entity work order incident have the value 770810001 in field cus1_workorderstatusvalue. However if a linked work order incident have the value 770810002 in field cus1_workorderstatusvalue then there shouldnt be shown any results / customer assets. I tried with standard CRM but couldnt get it to work. Then i thought i would need to create an outer joint but can't get that working either (usually it will display one or two results no matter what i try instead of zero).

3652.fetch.png

  
    
    
    
      
      
      
    
    
      
      
    
  

I have the same question (0)
  • Suggested answer
    Nya Ng Profile Picture
    185 on at

    Hi,

    I have tried to create the same custom fields ("cus1_parentassetid" and "cus1_workorderstatusvalue") into the two entities and edit the fetchXML.

    But there is a default field which related to the Customer Asset as a Parent Asset already. Its name is “msdyn_parentasset”.

    pastedimage1614245434008v1.png

    So I’m not sure what does “cus1_parentassetid” mean here.

    If you have to filter by the fields you set now, the fetchXML should look like the following:

     

      
        
        
        
        
          
        
        
          
            
              
              
            
          
        
      
    

     

    If this helped you, I'd appreciate it if you'd mark this as a Verified Answer, which may in turn help others as well.

    Best Regards,

    Nya

  • rskadk1 Profile Picture
    886 on at

    Hi,

    cus1_parentassetid is just a custom field with a unique number generated for each customer asset. It is not the same as parentasset.

    I tried your query. However it's still not working - something is not right.

    I have one work order incident with the cus1_workorderstatusvalue = 770810001

    And one work order incident with the cus1_workorderstatusvalue = 770810002

    Therefore in total 2 work order incidents related to my customer asset.

    If i run the query only with this condition  <condition attribute="cus1_workorderstatusvalue" operator="eq" value="770810001" /> i get 1 record.

    If i run the query (<condition attribute="cus1_workorderstatusvalue" operator="eq" value="770810001" />) with the same condition with operator equal and replaces workorderstatusvalue = 770810002  then i get 1 record.

    So i can conclude that there is 2 records found. This is as expected.

    Howvever when i combine the following i still get 1 result. I would have expected 0 results. As i have a record with the value 770810002 and i stated that that it should be not-equal that value?

             <condition attribute="cus1_workorderstatusvalue" operator="eq" value="770810001" />

             <condition attribute="cus1_workorderstatusvalue" operator="ne" value="770810002" />

    I suspect that the query is only validating the condition agains the first ressult found and not if many results are found?

  • Suggested answer
    Nya Profile Picture
    29,060 on at

    Hi,

    I can't understand exactly what kind of records you need to filter out.

    As you said, “I have one work order incident with the cus1_workorderstatusvalue = 770810001”, which we call it as incident A, “And one work order incident with the cus1_workorderstatusvalue = 770810002”, which we call it as incident B.

    If we follow your current filtering criteria, it is filtering all records with value equal to 770810001 and not equal to 770810002.

    The incident A fully satisfies this filter. (The value of A equals to 770810001 and doesn’t equal to 770810002.)

    If you are trying to combine the above two conditions of filtering out one record each to filter out records with a value equal to both 770810001 and 770810002 and get 0 records.

    Then the condition must be "eq" instead of "ne".

    Please specify which you need to filter.

    If this helped you, I'd appreciate it if you'd mark this as a Verified Answer, which may in turn help others as well.

    Best Regards,

    Nya

  • rskadk1 Profile Picture
    886 on at

    Hi again,

    You are right i currently have 2 records, incident A (770810001) and B (770810002)

    The problem is that i only wan't to get a result if the query can find a record with the value 770810001. However if it also finds a record with the value 770810002 it should return 0 results. (therefore i put the condition "ne" 770810002)

    Currently it will return a result if i use the follwing conditions. Where it should return 0 results because there is a record with the value 770810002.

    <condition attribute="cus1_workorderstatusvalue" operator="eq" value="770810001" />

    <condition attribute="cus1_workorderstatusvalue" operator="ne" value="770810002" />

  • Suggested answer
    Nya Profile Picture
    29,060 on at

    Hi,

    The condition you are using means filtering out all records whose value equals to 770810001 and does not equal to 770810002.

    It will definitely filter Incident A out.

    For the value of A is 770810001.

    770810001 = 770810001 and 770810001 770810002.

     

    If this helped you, I'd appreciate it if you'd mark this as a Verified Answer, which may in turn help others as well.

    Best Regards,

    Nya

  • rskadk1 Profile Picture
    886 on at

    The problem is that the filter should run against my main entity "Customer asset". So ONLY a cusstomer asset result is shown if all criterias are fulfilled (Search through all linked entitys where workorderstatusvalue equal to 770810001 and workorderstatusvalue not equal to 770810002). So if just 1 work order incident with the value 770810002 is found then no customer asset is shown).

    Currently the query finds 1 customer asset result even dough a linked work order incident record contains the value 770810002? How come am i getting 1 customer asset result?

  • Suggested answer
    Nya Profile Picture
    29,060 on at

    Hi,

    While this entire section of XML is specific to Customer Asset, the snippet within it is specific to Work Order Incident.

    For example, X (30 years old) has two children, called A (6) and B (8). Your XML is to search for people who has at least one child who is 6 years old and not 8 years old, not search for people whose children are all 6 years old and cannot be 8 years old.

     

    It means that your XML will only find a child record that matches the condition, rather than traversing all the child records to make sure they all match the condition.

     

    If this helped you, I'd appreciate it if you'd mark this as a Verified Answer, which may in turn help others as well.

    Best Regards,

    Nya

  • rskadk1 Profile Picture
    886 on at

    Hi,

    Allright that is why it isn't working as expected. Isn't there anyway the fetch xml can me modified to do this? (traversing all the child records)

  • Suggested answer
    Nya Profile Picture
    29,060 on at

    Hi,

    If you need to filter a Customer Asset whose child (Work Order Incident) records’ values all equal to 770810001 and do not equal to 770810002, the condition “do not equal to 770810002” is obviously redundant.

    It cannot be retrieved simply by fetchXML.

    However, you can get the number of records whose "cus1_parentassetid" equals to "116464" and have at least a child record whose "cus1_workorderstatusvalue" does not equal to "770810001".

      
        
        
        
        
          
        
        
          
            
              
            
          
        
      
    

    Subtract this number of filtered records from the total number of Customer Assets to get the number of Assets you need.

     

    If this helped you, I'd appreciate it if you'd mark this as a Verified Answer, which may in turn help others as well.

    Best Regards,

    Nya

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…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 70 Super User 2025 Season 2

#2
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 33 Most Valuable Professional

#3
Daniyal Khaleel Profile Picture

Daniyal Khaleel 32 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans