Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Fetch XML link-entity attribute value

(0) ShareShare
ReportReport
Posted on by 80

I have coded a fetch with a link-entity clause to get the value of an attribute in a related table that is working & returning the data I need [when tested using the XrmToolBox : FetchXml Tester tool].

The link-entity portion of the fetch statement is;-

"<link-entity name='new_ndisclientservice'  to='new_goalitem' from='new_supitemrefnum' link-type='inner' alias='SrvItm'> " +
         "<attribute name='new_costcentreid' />" +
"</link-entity>" +

 

When I run it in CRM using the XrmServiceToolkit, the FetchReturn.length = 2 (as I would expect on the basis of the criteria I am using) it is called via:-

var FetchReturn = XrmServiceToolkit.Soap.Fetch(FetchGoalNotes1Prsn(oFromDate, oToDate, oPrsnID));


So I know that the code is all OK up to that point. My issue is that when I try to get the value of  new_costcentreid  from the returned records the code stops running with no error message.

NB *  'new_costcentreid' is a look-up field in the 'new_ndisclientservice' entity.

To get the value of  new_costcentreid  I have tried various options including:-

  var oCostCentre1 = FetchReturn[0].Attributes["new_costcentreid"].value;

  var oCostCentre1 = FetchReturn[0].Attributes["new_costcentreid"].id;

I read another post that indicated that I needed to use the link alias so tried:-

  var oCostCentre1 = FetchReturn[0].Attributes["SrvItm.new_costcentreid"].value; 

 ..but that didn't work. Have tried a range of different ways but with no success - would appreciate any hints that may get this working.

Thanks in anticipation

Regards, Doug.

*This post is locked for comments

  • Barkuma Profile Picture
    80 on at
    RE: Fetch XML link-entity attribute value

    Thanks Arun,

    It turned out that this is how I got it to work:-

    var oCostCentre1 = FetchReturn[1].attributes["SrvItm.new_costcentreid"].value; 

    ...so a few variations from your suggestion:-

    1. the fetch actually returned the same record twice; once without the CostCentreID and once with the CostCentreID so it was only in the second record that I got what I was after.
    2. I was spelling Attributes (capital A) when it should have been lower case - this was the main reason my code didn't work.
    3. It did need the ["   ...    "] which your suggestion didn't have & without which it wouldn't work.

    Thanks again,

    Regards, Doug.

  • Verified answer
    Arun Vinoth Profile Picture
    11,615 Moderator on at
    RE: Fetch XML link-entity attribute value

    This should work.

    var oCostCentre1 = FetchReturn[0].attributes.SrvItm.new_costcentreid.value;

    [View:https://rajeevpentyala.com/2013/06/20/retrieve-records-with-fetchxml-using-jscript-crm-2011/]

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

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Kudos to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Microsoft Dynamics CRM (Archived)

#1
Mohamed Amine Mahmoudi Profile Picture

Mohamed Amine Mahmoudi 83 Super User 2025 Season 1

#2
Community Member Profile Picture

Community Member 52

#3
Victor Onyebuchi Profile Picture

Victor Onyebuchi 6

Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans