Skip to main content

Notifications

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

  • Suggested answer
    Raja Emmadisetty Profile Picture
    20 on at
    RE: FetchXml to retrieve segment member

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

    tempsnip.png

  • Raja Emmadisetty Profile Picture
    20 on at
    RE: FetchXml to retrieve segment member

    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

  • cloflyMao Profile Picture
    25,208 on at
    RE: FetchXml to retrieve segment member

    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 

  • Venedict Profile Picture
    1,235 on at
    RE: FetchXml to retrieve segment member

    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,208 on at
    RE: FetchXml to retrieve segment member

    Hi Teh,

    The maximum number is 5000.

    Regards,

    Clofly

  • Venedict Profile Picture
    1,235 on at
    RE: FetchXml to retrieve segment member

    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

  • Verified answer
    cloflyMao Profile Picture
    25,208 on at
    RE: FetchXml to retrieve segment member

    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
    RE: FetchXml to retrieve segment member

    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.

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

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

🌸 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…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Daivat Vartak (v-9davar) Profile Picture

Daivat Vartak (v-9d... 225 Super User 2025 Season 1

#2
Muhammad Shahzad Shafique Profile Picture

Muhammad Shahzad Sh... 106 Most Valuable Professional

#3
Eugen Podkorytov Profile Picture

Eugen Podkorytov 102

Overall leaderboard

Product updates

Dynamics 365 release plans