Skip to main content

Notifications

Announcements

No record found.

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 12

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

  • Suggested answer
    PabloCRP Profile Picture
    PabloCRP 1,088 on at
    RE: This code is working for particular opportunity to set the field. How we can set field for different opportunity?

    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

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Tip: Become a User Group leader!

Join the ranks of valued community UG leaders

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,494 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,307 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans