web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
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?  

I have the same question (0)
  • Community Member Profile Picture
    on at

    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.  

  • a33ik Profile Picture
    84,331 Most Valuable Professional on at

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

           }

       }

  • Abby Kong Profile Picture
    6 on at

    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

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

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Nagaraju_Matta Profile Picture

Nagaraju_Matta 121

#2
ManoVerse Profile Picture

ManoVerse 73 Super User 2026 Season 1

#3
Abhilash Warrier Profile Picture

Abhilash Warrier 66 Super User 2026 Season 1

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans