Skip to main content

Notifications

Community site session details

Community site session details

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

desactivate the add of multiple product on crm

(0) ShareShare
ReportReport
Posted on by

Hello 

I would like to desactivate the add of multiple product on a crm opportunité .

any suggestion  ? 

  • Community Member Profile Picture
    on at
    RE: desactivate the add of multiple product on crm

    hi , thanks this was  very helpfull , it actually solved the problem

  • Verified answer
    meelamri Profile Picture
    13,216 User Group Leader on at
    RE: desactivate the add of multiple product on crm

    Hi,

    please check this sample code:

    protected override void ExecuteCrmPlugin(LocalPluginContext localContext)
            {
                if (localContext == null)
                {
                    throw new InvalidPluginExecutionException("localContext");
                }
    
                IPluginExecutionContext context = localContext.PluginExecutionContext;
                IOrganizationService service = localContext.OrganizationService;
                ITracingService Logs = localContext.TracingService;
    
                Entity opportunityProduct = (Entity)context.InputParameters["Target"];
                EntityReference product = opportunityProduct.GetAttributeValue("productid");
                EntityReference opportunity = opportunityProduct.GetAttributeValue("opportunityid");
                
                // Define Condition Values
                var QEopportunityproduct_opportunityid = opportunity.Id.ToString();
                var QEopportunityproduct_productid = product.Id.ToString();
    
                
                // Instantiate QueryExpression QEopportunityproduct
                var QEopportunityproduct = new QueryExpression("opportunityproduct");
    
                // Add all columns to QEopportunityproduct.ColumnSet
                QEopportunityproduct.ColumnSet.AllColumns = false;
    
                // Define filter QEopportunityproduct.Criteria
                QEopportunityproduct.Criteria.AddCondition("opportunityid", ConditionOperator.Equal, QEopportunityproduct_opportunityid);
                QEopportunityproduct.Criteria.AddCondition("productid", ConditionOperator.Equal, QEopportunityproduct_productid);
    
                EntityCollection result = service.RetrieveMultiple(QEopportunityproduct);
                if (result.Entities.Count > 0)
                {
                    throw new InvalidPluginExecutionException("Error, duplicate product"); 
                }
    
                
    
            }

    The plugin will be registered at the creation of the product in preoperation.

  • Suggested answer
    meelamri Profile Picture
    13,216 User Group Leader on at
    RE: desactivate the add of multiple product on crm

    Sorry, I misunderstand your requirement. The only way is to use some code. You can use a plugin in the server side or a JS code to  Hide the + button if the subgrid contain an element.

  • Community Member Profile Picture
    on at
    RE: desactivate the add of multiple product on crm

    i actually tried this solution the key is activated but i do not see any result im still able to create duplicated and many product but i cannot see the job related this fields is empty :(

    3513.testtesttest.PNG

  • Suggested answer
    meelamri Profile Picture
    13,216 User Group Leader on at
    RE: desactivate the add of multiple product on crm

    No problem !

    I understand more your requirement. You need a simple JavaScript Code as a custom enable rule in ribbon workbench. Basically, you need to show the + button if the subgrid is empty. Hide the + button if the subgrid contain an element.

    Take a look at this example: 

    https://www.inogic.com/blog/2017/01/hide-add-button-on-a-subgrid-by-applying-custom-javascript-rule/

  • Community Member Profile Picture
    on at
    RE: desactivate the add of multiple product on crm

    hi sorry for disturbing but does the first solution desactivate this bottom the + 5466._2B00_.PNG

  • Suggested answer
    meelamri Profile Picture
    13,216 User Group Leader on at
    RE: desactivate the add of multiple product on crm

    Hi, 

    You can use alternate keys: 

    https://docs.microsoft.com/en-us/dynamics365/customerengagement/on-premises/customize/define-alternate-keys-reference-records

    2308.alternate-key.png

    you will get something like: 

    5504.pending.png

    Wait until the status change to Active. 

    If the status doesn't change, and gets stuck on "Pending", please refer to this blog to solve the problem: 

    https://community.dynamics.com/crm/b/passiondynamics/posts/alternate-key-creation-stuck-on-pending-status

  • Community Member Profile Picture
    on at
    RE: desactivate the add of multiple product on crm

    any other solution ?

  • Suggested answer
    meelamri Profile Picture
    13,216 User Group Leader on at
    RE: desactivate the add of multiple product on crm

    I believe that you need a plugin for this scenario. Basically, the plugin will be executed when a product is added to an opportunity in a preOperation.  You can raise an exception if it's a duplicate product.

  • Community Member Profile Picture
    on at
    RE: desactivate the add of multiple product on crm

    hi  thanks for your answer.

    i actually iwant to keep the add of products but for different product, so the sales cannot add the same product twice  .

    is that possible ?

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 the Engage with the Community forum!

This forum is your space to connect, share, and grow!

🌸 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…

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 Most Valuable Professional

#3
Eugen Podkorytov Profile Picture

Eugen Podkorytov 102

Overall leaderboard

Product updates

Dynamics 365 release plans