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

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
Tom_Gioielli Profile Picture

Tom_Gioielli 83 Super User 2025 Season 2

#2
Gerardo Rentería García Profile Picture

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

#3
#ManoVerse Profile Picture

#ManoVerse 40

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans