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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

How to add same items into subgrid of multiple entities

(0) ShareShare
ReportReport
Posted on by

Hi folks,

I want to add the same items into many entities' subgrids and out of the box function of CRM does not really support this I believe.

Illustrating example:

I want to add some Competitors records in the Competitor subgrid of Lead entity:

lead-entity.PNG

But I want to add the same Competitors for many other lead entities

Is there any idea to achieve this? Any ideas will be much appreciated!

*This post is locked for comments

I have the same question (0)
  • Sreevalli Profile Picture
    3,264 on at

    Hi,

    Create N:N relationship between Lead and Competitor and modify the competitor subgrid reference to N:N relationship. so that you can use the same competitor on more than one lead

  • Community Member Profile Picture
    on at

    Hi Sreevalli,

    Thank you for sharing your idea. I think we are not really on the same page here.

    Current situation is that I can add Competitors to the Lead sub grid, I have to open each and every Lead record that I want to add the Competitor and perform the same adding again and again. The goal is to do this in one go.

    I am wondering if we could somehow customize, maybe create a button on Ribbon bar under Lead view, select all the lead that we want to add Competitors, then click that button, then select the Competitor to add into the subgrids of the selected Lead records.

    Do you think we could do that?

  • Sreevalli Profile Picture
    3,264 on at

    Hi,

    Yes, we can do this with a ribbonbutton and Javascript.

    Add a button on lead homegrid and subgrid(advance-find). on button click it will open a popup to choose all compitatiors (same as Add to MarketingList button on lead homegrid), upon page submission we can add our logic to associate lead and competitors.

    sample code from worklogs,

    function AddToCompetitor() {
        debugger;
        var lookupOptions = {};
        lookupOptions.allowMultiSelect = true;
        lookupOptions.defaultEntityType = "competitor";
        lookupOptions.entityTypes = ["competitor"];
        Xrm.Utility.lookupObjects(lookupOptions).then(
            function AddCompetitorCallback(selectedCompitetors) {
                debugger;
    
                var recordIds =  // fetch the selected lead ids here
                for (var l = 0; l < recordId(s); l++) //loop for selected leads
                {
                for (var c = 0; c < selectedCompitetors.length; c++) { //loop for selected compitetors
                    // add your logic
                    }
                }
            }
            }


  • Community Member Profile Picture
    on at

    Hi Sreevalli,

    Thank you so much for your suggestion. I tried the same code and it looks like this not really working though

  • Suggested answer
    Sreevalli Profile Picture
    3,264 on at

    What is the error, It should work same as "Add to Marketinglist" button on lead page

  • Abhishek Gupta Profile Picture
    2,003 on at

    Hi,

    Since you are aware of a list of competitors. Create a console application, write a code activity which read lead records from excel and store it into a data table. Iterate the data table and associate lead with the known competitors. You can extract list of lead records from crm through advance find. Hope it helps.

    Thanks.

  • Suggested answer
    Dynamics365 Rocker Profile Picture
    7,755 on at

    You can create Many to many relationship between lead and competitor. This will resolve your issue.

  • Suggested answer
    RaviKashyap Profile Picture
    55,410 Moderator on at

    Hi Du Tran,

    Competitor subgrid on the lead entity is an out of box  N:N relationship between Lead & Competitor and is not available to insert the data directly. As you have noticed, you can only associated records from lead to competitor subgrid. The only option is to built / customize is to have a ribbon button which calls the JavaScript to open the list of competitor to select from and then associate it with the selected leads (Sample code shared by Sreevalli above) but this requires more effort to register it on ribbon button, get the selected leads and then get the selected contact and then associate the record will be another challenge. If you are not a developer then this may be difficult.

    I am not sure how many of the records you have already added but if can, I would suggest to create a new entity with 2 fields(lead & competitor). Add the subgrid on lead for this entity. Now as this is an entity, you can use out of box import excel option to import data.

    Hope this helps.

  • Community Member Profile Picture
    on at

    Hi guys, thank you for your suggesting, I think the relationship is already added

    Hi Sreevalli, 

    I will share the error, could you please help?

    I create this button in Ribbon bar to add:

    reddy2.PNG

    I follow this: 

    https://community.dynamics.com/crm/f/117/t/273328 to get the user list and display in the new window after button is clicked

    reddy2.PNG

    When click OK, the error happens

    reddy3.PNG

    "_error":{"Code":null,"Description":"A potentially dangerous Request.Path value was detected from the client (&).","DisplayText":"","ErrorCode":0,"RedirectToEdit":false,"SerializedEntity":null,"SerializedException":"Unhandled exception: \u000aException type: System.ServiceModel.FaultException`1[Microsoft.Xrm.Sdk.OrganizationServiceFault]\u000aMessage: System.Web.HttpException (0x80004005): A potentially dangerous Request.Path value was detected from the client (&).\u000d\u000a   at System.Web.HttpRequest.ValidateInputIfRequiredByConfig()\u000d\u000a   at System.Web.HttpApplication.PipelineStepManager.ValidateHelper(HttpContext context): Microsoft Dynamics CRM has experienced an error. Reference number for administrators or support: #2640A5B1Detail: \u000d\u000a<OrganizationServiceFault xmlns:i=\"http:\/\/www.w3.org\/2001\/XMLSchema-instance\" xmlns=\"http:\/\/schemas.microsoft.com\/xrm\/2011\/Contracts\">\u000d\u000a  <ActivityId>16a891ee-83de-4920-a007-169e4a33f165<\/ActivityId>\u000d\u000a  <ErrorCode>-2147220970<\/ErrorCode>\u000d\u000a  <ErrorDetails xmlns:d2p1=\"http:\/\/schemas.datacontract.org\/2004\/07\/System.Collections.Generic\" \/>\u000d\u000a  <Message>System.Web.HttpException (0x80004005): A potentially dangerous Request.Path value was detected from the client (&amp;).\u000d\u000a   at System.Web.HttpRequest.ValidateInputIfRequiredByConfig()\u000d\u000a   at System.Web.HttpApplication.PipelineStepManager.ValidateHelper(HttpContext context): Microsoft Dynamics CRM has experienced an error. Reference number for administrators or support: #2640A5B1<\/Message>\u000d\u000a  <Timestamp>2019-04-30T05:56:11.6277776Z<\/Timestamp>\u000d\u000a  <ExceptionRetriable>false<\/ExceptionRetriable>\u000d\u000a  <ExceptionSource i:nil=\"true\" \/>\u000d\u000a  <InnerFault i:nil=\"true\" \/>\u000d\u000a  <OriginalException i:nil=\"true\" \/>\u000d\u000a  <TraceText i:nil=\"true\" \/>\u000d\u000a<\/OrganizationServiceFault>","Title":""}}

  • Suggested answer
    Sreevalli Profile Picture
    3,264 on at

    So you are trying to add users to account, now its confusing - we started at Lead and Competitor.

    Any ways what is the relationship between user and account, I mean how you want to add a user to account? Is it owner?

    The lookup window looking weird to me, which version of CRM it is? below is lookupoptions code for user entity

    function AddToCompetitor() {

       debugger;

       var lookupOptions = {};

       lookupOptions.allowMultiSelect = true;

       lookupOptions.defaultEntityType = "systemuser";

       lookupOptions.entityTypes = ["systemuser"];

       Xrm.Utility.lookupObjects(lookupOptions).then(

           function AddCompetitorCallback(selectedCompitetors) {

               debugger;

               var recordIds =  // fetch the selected lead ids here

               for (var l = 0; l < recordId(s); l++) //loop for selected leads

               {

               for (var c = 0; c < selectedCompitetors.length; c++) { //loop for selected uers

                   // add your logic

                   }

               }

           }

           }

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
ScottDurow Profile Picture

ScottDurow 2

#2
GJones Profile Picture

GJones 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans