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

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
Pallavi Phade Profile Picture

Pallavi Phade 98

#2
Tom_Gioielli Profile Picture

Tom_Gioielli 60 Super User 2025 Season 2

#3
Gerardo Rentería García Profile Picture

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

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans