Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Unanswered

CRM Plugin to Check and Modify OpportunityEnt["ProposalNumber"] doesn't update in CRM but stepping through code in debug shows no errors.

(0) ShareShare
ReportReport
Posted on by

Hello I have created a plugin that executes upon Opportunity create.  The purpose of the plug in the check if the recently create Opportunity is a duplicate of another opportunity.  We will define a duplicate opportunity by having identical Proposal Numbers as a existing Opportunity.

If a duplicate is detected then we want to modify the proposal number programmatically and save it.  

My current issue is that after saving the opportunity, the plugin seems to run but does not change the value of the intended field. 

I have written a plugin previously that will auto increment a project number field on a Job entity, I based my new plugin code off of this previous plugin.  The auto increment Job plugin works as expected, but the only difference between the two plugins is that, the new one has to query all the Opportunity entities in order to check for duplicates.  This section of code might be the culprit because this is where I query for all the Opp entities, and then proceed to add the Proposal Number attribute of each entity into a list of strings.  I think this area is the culprit because it takes a little bit to execute (about 11 seconds), when I step through the code. 

List listOfProjectNumbers = new List();
var serviceContext = new OrganizationServiceContext(service);
string fetchQuery = @"
               
                  
                         
                  
             ";
EntityCollection results = service.RetrieveMultiple(new FetchExpression(fetchQuery));
            
foreach (var c in results.Entities)
    {
        try
        {
            listOfProjectNumbers.Add(c.Attributes["cmc_proposalnumber"].ToString());
        }
        catch (Exception ex)
        {
            Console.Write(ex.Message);
        }
    }

Do you guy have any insight in what the potential issue could be?  

  • Abby Kong Profile Picture
    6 on at
    RE: CRM Plugin to Check and Modify OpportunityEnt["ProposalNumber"] doesn't update in CRM but stepping through code in debug shows no errors.

    Hi cont_hngo,

    Is your plugin registered against Pre or Post of Create?

    If the plugin is Post Create, please call Update explicitly to make sure the assigned attribute in the plugin code is saved.

    Regards,

    Abby

  • a33ik Profile Picture
    84,331 Most Valuable Professional on at
    RE: CRM Plugin to Check and Modify OpportunityEnt["ProposalNumber"] doesn't update in CRM but stepping through code in debug shows no errors.

    Hello,

    To update record you have to call Update method of service like:

    var serviceContext = new OrganizationServiceContext(service);

    string fetchQuery = @"

               <fetch mapping='logical'>  

                   <entity name='opportunity'>  

                       <attribute name='cmc_proposalnumber'/>    

                   </entity>  

               </fetch> ";

    EntityCollection results = service.RetrieveMultiple(new FetchExpression(fetchQuery));

    foreach (var c in results.Entities)

       {

           try

           {

               listOfProjectNumbers.Add(c.Attributes["cmc_proposalnumber"].ToString());

               service.Update(listOfProjectNumbers);

           }

           catch (Exception ex)

           {

               Console.Write(ex.Message);

           }

       }

  • Community Member Profile Picture
    on at
    RE: CRM Plugin to Check and Modify OpportunityEnt["ProposalNumber"] doesn't update in CRM but stepping through code in debug shows no errors.

    The issue was the cmc_proposalnumber field is a string field.  So when I create a new Proposal Number, my custom p number is a integer object.  By converting my integer object to a string, this solved all my issues.  

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

#3
Vahid Ghafarpour Profile Picture

Vahid Ghafarpour 82 Super User 2025 Season 1

Overall leaderboard

Product updates

Dynamics 365 release plans