Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

How to add same items into subgrid of multiple entities

Posted on by Microsoft Employee

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

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: How to add same items into subgrid of multiple entities

    Thank you for your suggestion.

    Account will have team members aka User entity. Account record will have the subgrid of Users. So I can add User to Account in that way. They have N;N relationship too.

    It is custom code in community.dynamics.com/.../273328 so it might look weird even though my org has latest April release.

    Not sure why when I click OK, it throws error like above though.

  • Suggested answer
    Sreevalli Profile Picture
    Sreevalli 3,256 on at
    RE: How to add same items into subgrid of multiple entities

    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

                   }

               }

           }

           }

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: How to add same items into subgrid of multiple entities

    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
    RaviKashyap Profile Picture
    RaviKashyap 55,410 on at
    RE: How to add same items into subgrid of multiple entities

    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.

  • Suggested answer
    Dynamics365 Rocker Profile Picture
    Dynamics365 Rocker 7,755 on at
    RE: How to add same items into subgrid of multiple entities

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

  • Abhishek Gupta Profile Picture
    Abhishek Gupta 2,001 on at
    RE: How to add same items into subgrid of multiple entities

    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
    Sreevalli Profile Picture
    Sreevalli 3,256 on at
    RE: How to add same items into subgrid of multiple entities

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

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: How to add same items into subgrid of multiple entities

    Hi Sreevalli,

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

  • Sreevalli Profile Picture
    Sreevalli 3,256 on at
    RE: How to add same items into subgrid of multiple entities

    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
    Community Member Microsoft Employee on at
    RE: How to add same items into subgrid of multiple entities

    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?

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans