web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Suggested Answer

Adding Opportunity Ids in array using C#

(0) ShareShare
ReportReport
Posted on by

Hi Team,

We want to fetch record id of opportunity and then store it in string array using C#. Could you help us please?

Many Thanks,

Mayur

I have the same question (0)
  • Suggested answer
    meelamri Profile Picture
    13,218 User Group Leader on at

    Hi, 

    I add two lines to your code. (found in your last post) 

    var fetchData = new

                   {

                       willis_probability = "7",

                       willis_inceptiondate = "01-25-2020"

                   };

                   var fetchXml = $@"

    <fetch top='50'>

     <entity name='opportunity'>

       <attribute name='willis_opportunityid' />

       <filter type='and'>

         <condition attribute='willis_probability' operator='eq' value='{fetchData.willis_probability/*7*/}'/>

         <condition attribute='willis_inceptiondate' operator='on-or-before' value='{fetchData.willis_inceptiondate/*01-25-2020*/}'/>

       </filter>

     </entity>

    </fetch>";

                   EntityCollection result = _serviceProxy.RetrieveMultiple(new FetchExpression(fetchXml));

                   List<Guid> oppIds = new List <Guid>();

                   foreach (var c in result.Entities)

                   {

                       System.Console.WriteLine(c.Attributes["name"]);

                       oppIds.add(c.Id);

                   }

  • Suggested answer
    Vijay Tailor Profile Picture
    431 on at

    You can also use QueryExpression / Odataquery Endpoint.

    QueryExpression -

    // Instantiate QueryExpression QEopportunity
    var QEopportunity = new QueryExpression("opportunity");
    QEopportunity.TopCount = 50;

    // Add columns to QEopportunity.ColumnSet
    QEopportunity.ColumnSet.AddColumns("opportunityid", "name");

    Odata Query endpoint - XXXX.crm8.dynamics.com/.../opportunities

  • Community Member Profile Picture
    on at

    Hi Mehdi,

    Actually we have to do it from web API. We have to fetch data from API and then wwe have to add in array. Can we do it from API?

  • meelamri Profile Picture
    13,218 User Group Leader on at

    Hi,

    can you please give more details ?

  • Suggested answer
    Johao Larios Profile Picture
    1,795 on at

    Hello there, 

    Yes, you could achieve this using the webapi: https://docs.microsoft.com/en-us/powerapps/developer/common-data-service/webapi/retrieve-and-execute-predefined-queries#use-custom-fetchxml 

    So, you could create a view using the UI, download the fetch for that view then encode that fetch and use it with above webapi query. 


    Please let us know if you have any more questions or please mark this as answered if we have answered your question. 


    regards, 

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Muhammad Shahzad Shafique Profile Picture

Muhammad Shahzad Sh... 69 Most Valuable Professional

#2
ManoVerse Profile Picture

ManoVerse 55 Super User 2026 Season 1

#3
11manish Profile Picture

11manish 37

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans