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 :
Microsoft Dynamics CRM (Archived)

This code is working for particular opportunity to set the field. How we can set field for different opportunity?

(0) ShareShare
ReportReport
Posted on by 14

string fetch = @"<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='true'>

  <entity name='hnny_class'>

    <attribute name='hnny_classid' />

    <attribute name='hnny_name' />

    <attribute name='createdon' />

    <order attribute='hnny_name' descending='false' />

    <link-entity name='hnny_class_opportunity' from='hnny_classid' to='hnny_classid' visible='false' intersect='true'>

      <link-entity name='opportunity' from='opportunityid' to='opportunityid' alias='aa'>

        <filter type='and'>

          <condition attribute='opportunityid' operator='eq' uiname='' uitype='opportunity' value='" + initialRelatedEntity.Id + "' />";

        fetch+=@"</filter>

      </link-entity>

    </link-entity>

  </entity>

</fetch>";

 

                FetchExpression exep = new FetchExpression(fetch);

                EntityCollection collection = service.RetrieveMultiple(exep);

               // throw new Exception("Count"+collection.TotalRecordCount);

                if (collection.Entities.Count > 0)

                {

                    string classNames = "";

                    foreach (Entity classes in collection.Entities)

                    {

                        if (classNames == "")

                            classNames = classes.Attributes.Contains("hnny_name") ? (String)classes["hnny_name"] : string.Empty;

                        else

                            classNames += classes.Attributes.Contains("hnny_name") ? (String)classes["hnny_name"] : string.Empty;

                    }

                    Entity opp = new Entity("opportunity", new Guid("{C2A03262-E8B8-E911-A961-000D3A12468B}"));

                    opp["hnny_classes"] = classNames; // use classfiled logcal name

                    service.Update(opp);

 

                }

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    PabloCRP Profile Picture
    1,088 on at

    at this line :

           Entity opp = new Entity("opportunity", new Guid("{C2A03262-E8B8-E911-A961-000D3A12468B}"));

    you have to retrieve the GUID of the oportunity by Target, Image or Query.

       Entity opp = new Entity("opportunity", opportunityId);

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 > 🔒一 Microsoft Dynamics CRM (Archived)

#1
ScottDurow Profile Picture

ScottDurow 2

#2
GJones Profile Picture

GJones 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans