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 :
Microsoft Dynamics 365 | Integration, Dataverse...
Answered

Create a Record from a Record in a Sub-Grid

(0) ShareShare
ReportReport
Posted on by

Hello,

I have a custom entity that displays as a sub-grid in another entity (Leads).  This custom entity allows additional names to be recorded against a primary record.

It's working fine.  Now I would like to create a new contact record from the custom entity without leaving the sub-grid in the Leads entity. How do I do that?

Workflow and Flow allowed me to set something up but they don't actually work.  The workflow creates one blank record in contacts no matter how many records I select to run against.

The flow does nothing. The trigger is "when a record is selected" in the custom entity.

I want the user to be able to add many names to the custom entity but select which ones should actually be created as contacts after the lead is qualified. 

Thanks!

Beth

I have the same question (0)
  • cloflyMao Profile Picture
    25,210 on at

    Hi Jones,

    I thought you should create a web resource button or ribbon button to trigger create function with selected rows data by javascript:

    function createContactRecordFromLeadSubgrid() {
      
      var data = [];
      var selectedRows = formContext.getControl("Your sub-grid name").getGrid().getSelectedRows();
      selectedRows.forEach(function(selectedRow, i) {
        data.push(selectedRow.getData().getEntity().attributes.getByName("attribute you want").getValue());
      });
    
      var contactData = {
        "attr": data.toString()
      }
    
      Xrm.WebApi.createRecord("contact", contactData).then(
        function success(result) {
          console.log("Contact created with ID: "   result.id);
        },
        function(error) {
          alert(error.message);
        }
      );
    
    }

    Could you share me more details about how would you like to perform create contact record function when you had selected some rows in sub-grid?

    Regards,

    Clofly

  • Suggested answer
    Roma Gupta Profile Picture
    725 on at

    Hi Jones

    To add many names, do you want the user to upload user list as csv? Or you want a form to open up and do the process for 10 times if they want to create 10 users?

    The first one you can make use of notes section or a custom upload for uploading csv & in backed you can create contact with the details mentioned. This would save user time.

  • Community Member Profile Picture
    on at

    Hi Clofly,

    Thanks for the response!

    When the user selects specific records in the sub-grid a contact record would be created with basic contact info (first and last name, title, email, . . .). But the contact records are only created if the lead is qualified.

    Then after they're created or fail a success or error message.

  • Community Member Profile Picture
    on at

    Hi Roma,

    Thanks for the response!

    The names would already be created. I want selected additional lead names associated with a primary lead record converted to contacts after the primary lead has been qualified.

    It may be that over the course of discovery the salesperson encounters 10 more people who should get marketing materials but we don't necessarily want 11 lead records at the same company in the system. So the 10 are related to the primary lead through a custom entity.

    Once the primary lead is qualified maybe only 5 of the additional names really need to be contacts. The salesperson ideally can choose those from the sub-grid and make them contacts instead of actually going directly to the custom entity. The original 10 would remain in the custom entity associated with leads, though.

  • Verified answer
    cloflyMao Profile Picture
    25,210 on at

    Hi Jones,

    I thought we should add a custom ribbon button at first to trigger your contact create function.

    1. Download icons for custom ribbon button:

    a 16x16 png icon, a 32x32 png icon, a 16x16 svg icon

    You could download free resources in this website: https://icons8.com/

    2. Create a solution and import your lead entity ,custom javascript and icon files as web resources into it.

    3. Download Ribbon Workbench and import it as solution.

    4. Import your lead solution in ribbon workbench.

    5. Drag a button element in third section(form), I added it at left of New button, and make properties configuration to the button like screenshot below:

    pastedimage1574307373651v1.png

    6. Add an Enable rule to the button:

    pastedimage1574310239335v3.png

    7. displayButton function, only display the button when lead is qualified:

      function displayButton() {
        if (Xrm.Page.data.entity.getId() != null && Xrm.Page.data.entity.getId() != "") {
          var id = Xrm.Page.data.entity.getId().replace('{', '').replace('}', '');
          Xrm.WebApi.retrieveRecord("lead", id, "?$select=statuscode").then(
            function success(result) {
              if (result.statuscode == 3) {
                return true;
              } else {
                return false;
              }
            },
            function(error) {
              alert(error.message);
            }
          );
        } else {
          return false;
        }
      }

    8. Add createContactRecord function to the button(1), enable the show/hide rule for the button(2)

    pastedimage1574310327509v4.png

    9. createContactRecord  function

      function createContactRecordFromLeadSubgrid(primaryControl) {
        var formContext = primaryControl;
        if (formContext.getControl("Competitors").getGrid().getSelectedRows().getLength() != 0) {
          var data = [];
          var selectedRows = formContext.getControl("Competitors").getGrid().getSelectedRows();
          selectedRows.forEach(function(selectedRow, i) {
            data.push(selectedRow.getData().getEntity().attributes.getByName("name").getValue());
          });
          alert(data);
        } else {
          alert("At least one record is required to create a contact record.");
        }
      }

    10. publish both javascript web resource and ribbon button solution

    (I test in OOB competitor sub-grid)

    11. No selected rows:

    pastedimage1574310631845v6.png

    12. Get selected rows data

    pastedimage1574310543516v5.png

    Now we are close to your final requirement:

    how would you like to create a new contact record? from one selected custom entity record or multiple? and which attributes are required?

    Regards,

    Clofly

  • Suggested answer
    Roma Gupta Profile Picture
    725 on at

    Hi Jones

    Thank you for the clarification. In that case, add a button on sub-grid, the selected records would go thru. Clofly has already suggested the solution.

    It depends on you where the button needs to be placed.

    Regards

    Roma

  • cloflyMao Profile Picture
    25,210 on at

    Hi Jones,

    We're waiting for your feedback and hope your problem could be solved. :)

    Regards,

    Clofly

  • Community Member Profile Picture
    on at

    Hi Clofly and Roma,

    Thanks for your suggestions.  I think they will work but I haven't had a chance to try them.

    I'm not a coder but the instructions look straightforward enough that I should be able to muddle through them.

    Thanks again!

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 > Microsoft Dynamics 365 | Integration, Dataverse, and general topics

#1
Martin Dráb Profile Picture

Martin Dráb 47 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 38 Super User 2025 Season 2

#3
#ManoVerse Profile Picture

#ManoVerse 31

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans