Skip to main content

Notifications

Announcements

No record found.

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

  • Suggested answer
    Johao Larios Profile Picture
    1,795 on at
    RE: Adding Opportunity Ids in array using C#

    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, 

  • meelamri Profile Picture
    13,216 User Group Leader on at
    RE: Adding Opportunity Ids in array using C#

    Hi,

    can you please give more details ?

  • Community Member Profile Picture
    on at
    RE: Adding Opportunity Ids in array using C#

    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?

  • Suggested answer
    Vijay Tailor Profile Picture
    431 on at
    RE: Adding Opportunity Ids in array using C#

    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

  • Suggested answer
    meelamri Profile Picture
    13,216 User Group Leader on at
    RE: Adding Opportunity Ids in array using C#

    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);

                   }

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 > 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... 91

#3
Vahid Ghafarpour Profile Picture

Vahid Ghafarpour 78 Super User 2025 Season 1

Overall leaderboard

Product updates

Dynamics 365 release plans