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,...
Answered

FetchXml to retrieve segment member

(0) ShareShare
ReportReport
Posted on by 1,235

Hi All,

I'm using advanced find to retrieve the dynamic  and static segment member and there is result return. Then I try to download the fetchxml file from the advanced find and put in my csharp code. However seem there is no result return.

Then I copied the fetchxml file into FetchXmlTester in Xrmtoolbox, it also didn't return any result. FYI, my segment have 1 contact in the advanced find result. Below is my fetchxml

  
    
    
    
    
    
    
      
        
      
    
  

Anything I missed out?

Thanks.

Regards,

Teh

I have the same question (0)
  • Venedict Profile Picture
    1,235 on at

    I just realized that seem the FetchXml way to retrieve the records is deprecated.

    POST {{OrgUrl}}/api/data/v9.0/msdyncrm_FetchContactsByQuery
    {
        "Query":"(SEGMENT(SEGMENT_CRM_ID_e1fa7fdc5c78ea11a811000d3a8e8fcc)).ORDERBY(fullname ASC).SKIP(0).TAKE(15).SELECT(contactid)",
        "FetchXml":"","OwningBusinessUnit":"0b4b85cc-7f6c-ea11-a811-000d3a54d359",
        "Scope":270100000,
        "TimeZone":null
    }

    I saw there is a recommended way to retrieve it. However, I'm not sure how to convert this code in Plugin or custom workflow?

    I'm try to run the {orgurl}/api/data/v9.0/msdyncrm_FetchContactsByQuery to retrieve the metadata, but I cant find msdyncrm_FetchContactsByQuery in the list.

    Does anyone know how can I convert the code above to use in the Plugin or Custom workflow?

    Thanks.

  • Verified answer
    cloflyMao Profile Picture
    25,210 on at

    Hi Teh,

    From metadata definition, calling "msdyncrm_FetchContactsByQuery" in Plugin or Workflow could be regarded as calling an action by organizationService.

    pastedimage1589167218515v1.png

    String fetchxml = ""  
                            ""  
                            ""  
                            ""  
                            ""  
                            ""  
                            ""  
                            ""  
                            ""  
                        "";
    
    OrganizationRequest orgRequest = new OrganizationRequest("msdyncrm_FetchContactsByQuery");
    orgRequest.Parameters.Add("Query", "(SEGMENT(SEGMENT_CRM_ID_237349c9428fea11a811000d3a80c3f7)).ORDERBY(fullname ASC).SKIP(0).TAKE(15).SELECT(contactid)");
    orgRequest.Parameters.Add("FetchXml", fetchxml);
    orgRequest.Parameters.Add("Scope", 270100000);
    orgRequest.Parameters.Add("TimeZone", null);
    
    OrganizationResponse orgResponse = organizationService.Execute(orgRequest);

    Regards,

    Clofly

  • Venedict Profile Picture
    1,235 on at

    Hi Clofly,

    Thanks for your reply. Using your sample code, I managed to get the segment member now.

    I noticed that in your query, you are limit to 1st 15 contacts, correct? Is there any limit of the max contact that can return from the query?

    Thanks.

    Regards,

    Teh

  • cloflyMao Profile Picture
    25,210 on at

    Hi Teh,

    The maximum number is 5000.

    Regards,

    Clofly

  • Venedict Profile Picture
    1,235 on at

    Hi Clofly,

    Thanks for your prompt reply. What if we have more than 5000 of segment member? How to retrieve all member in the segment?

    Thanks.

    Regards,

    Teh

  • cloflyMao Profile Picture
    25,210 on at

    Hi Teh,

    In general fetchXml query, we could break the limitation with "paging cookie".

    However, currently we are calling an action, and fetchxml here is only a parameter, 

    in other word, we are not running a general fetchxml query, so I'm not sure whether there is way to handle current situation.

    I suggest you could open a support ticket to ask whether the maximum number could be upgraded at back-end for "msdyncrm_FetchContactsByQuery" if you have requirement about large number query.

    Regards,

    Clofly 

  • Raja Emmadisetty Profile Picture
    20 on at

    Hi

    I tried to call the action in Power Automate but I am facing invalid query syntax issue.

    [{"__type":"SegmentationCrmApiResponseError:#Microsoft.Dynamics.Crm.MarketingPlugins.Plugins.Segmentation.Contracts","ErrorCode":"QuerySyntaxError","Message":"Invalid query language: \u000aLine: 0, Position: 32, Column: 32: Number cannot be followed by a letter."}]

    Power Automate looks like below.

    pastedimage1622480688445v1.png

  • Suggested answer
    Raja Emmadisetty Profile Picture
    20 on at

    No worried. It is working now. Flow looks like this . I had to get segment query name and use compose .

    tempsnip.png

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 83 Super User 2025 Season 2

#2
Gerardo Rentería García Profile Picture

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

#3
#ManoVerse Profile Picture

#ManoVerse 40

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans