Search code examples
odatadynamics-crmsharepoint-2013

Looking for the odata query that returns the Sharepoint Site URL for a document location for a CRM account


For a given account I need to find the URL of the Sharepoint Site.

I can get the Sharepoint document location, but I really need the URL of the "parent"- Sharepoint Site.

I have come this far:

https://NOTMYORG.crm4.dynamics.com/XRMServices/2011/OrganizationData.svc/SharePointDocumentLocationSet$expand=sharepointdocumentlocation_parent_sharepointsite&$select=Name,sharepointdocumentlocation_parent_sharepointsite&$filter=RegardingObjectId/Id eq (guid'{0537BE88-ECFB-E311-A8DE-2C59E5419D10}')

But now I am stuck.


Solution

  • I think you have to use the ParentSiteOrLocation attribute from SharePointDocumentLocation instead. And continue querying until you get to a SharePointSite as parent, then query that SharePointSite for AbsoluteURL.

    The ParentSiteOrLocation attribute will get you a entityreference to the parent record. This can be a SharePointDocumentLocation or a SharePointSite, so you have to check the logicalname of the entityreference. And then either continue querying SharePointDocumentLocation with the id of the parent or SharePointSite until you get the URL of the site.

    Get the SharePointDocumentLocation:

    https://NOTMYORG.crm4.dynamics.com/XRMServices/2011/OrganizationData.svc/SharePointDocumentLocationSet?$select=ParentSiteOrLocation&$filter=RegardingObjectId/Id eq (guid'{0537BE88-ECFB-E311-A8DE-2C59E5419D10}')

    Then get SharePointSite if the parent of SharePointDocumentLocation is SharePointSite:

    https://NOTMYORG.crm4.dynamics.com/XRMServices/2011/OrganizationData.svc/SharePointSiteSet(guid'ID from ParentSiteOrLocation')?$select=AbsoluteURL

    A SharePointSite can also have a parent. The attribute AbsoluteURL on SharePointSite only have a value when it has no parent, if it has a parent, the RelativeURL attribute will have a value.