Customization

Clone records without code

People frequently want to create a new record based on an existing record. This can save a lot of time that would otherwise be spent entering data.

There have been a number of solutions to enable this functionality in earlier versions of Microsoft Dynamics CRM, but these solutions generally require the creation of custom buttons and JScript code.

However, in Microsoft Dynamics CRM you can achieve the same result without writing any code at all. This article describes how to add the capability to "clone" a Lead record, but the same principles can be applied to just about any kind of record in Microsoft Dynamics CRM.

The basic procedure is:

  1. Create a self-referencing relationship.
  2. Configure relationship mappings.
  3. Save and publish the entity.
  4. Create a cloned record.

    Note

    You must have the System Administrator or System Customizer role to perform these steps.

On This Page

Create a self-referencing relationship

Configure relationship mappings

Save and publish

Create a cloned record

Create a self-referencing relationship

  1. In the Navigation Pane, click System Settings, click Customization, and then click Customize Entities.
  2. Locate the Lead entity and double-click it.
  3. Under Details, select N:1 Relationships and then click New Many-to-1 Relationship.
  4. Enter the following in the Relationship Definition section:

    Field

    Value

    Description

    Primary Entity

    Lead

    This creates a self-referential relationship.

    Default Name

    new_clone_source_lead

    This must be unique. You can modify it to make it meaningful to people who may see this name when creating reports.

  5. Enter the following in the Relationship Attribute section:

    Field

    Value

    Description

    Display Name

    [This record cloned from]

    When the relationship is created, the Relationship Attribute is a lookup field that could be added to the Lead form. However, there is no reason to do this. Therefore, provide a display name that indicates clearly what the data in the field represents.

    Name

    new_clone_source_lead

    This name must be unique. You should give it a name meaningful to people who may see this name when creating reports.

    Description

    This lookup field is part of the relationship that enables users to "clone" records from an associated view. This field should not be displayed on the Lead form.

    Record why the field exists. This will help document why the field and relationship are there.

  6. Enter the following in the Navigation Pane Item for Primary Entity section:

    Field

    Value

    Description

    Display Option

    Use Custom Label

    This indicates that you will specify a label using the Custom Label field.

    Custom Label

    Cloned Leads

    This is the text that will display in the Lead page navigation area so that people can view the associated view created by this relationship. This is where people will go to "clone" a lead.

  7. Click Save, but don't close the relationship form yet.

Configure relationship mappings

After you have created the relationship, you can modify any mappings defined in the relationship. When you create a new record from an associated view, mappings define which data from the current record is copied over to the new record. People can still change the values of the fields before they save the record.

Unless you intentionally want to create a duplicate record, make sure you don't map fields that uniquely identify the source record, such as any name, mobile phone number, or e-mail fields.

Because some fields are automatically mapped when the relationship is created, there are three ways to approach this:

  • Remove all the fields that you don't want. The entity may have many attributes that aren't necessarily included on the form. Any attributes not included on the form will not be mapped.
  • Remove all the fields and add back only those you need. This may be faster if you only have a few fields that are important to you. You can only map one attribute at a time, so this process can be laborious if you need to map a lot of attributes.

    Note

    You will not be able to delete any lookup fields.

  • Generate mappings. In the More Actions menu you will find the Generate Mappings option. This will automatically generate mappings based on common field names and data types. When you have a self-referencing relationship, this will generate a nearly 100% match. These mappings will override any existing mappings. You might use this if you have removed too many mappings and want to start over and add them all back again.

Procedure to remove a field mapping

  1. In the Mappings area of the relationship form, select one or more attribute mappings.

    Tip

    You can hold down the Ctrl key and select multiple mappings.

  2. Click the Delete selected attribute mappings button (the "X" button) in the menu toolbar.

Procedure to map a field

  1. In the Mappings area of the relationship, on the Actions toolbar, click New for each new mapping.
  2. In the Create Attribute Mapping dialog box, select the source attribute from Source Entity Attributes, select the target attribute from Target Entity Attributes, and then click OK.

    Note

    When you select attributes, consider the mapping requirements:

    • Both attributes must be of the same type and the same format.
    • The length of the target attribute must be equal to or greater than the length of the source attribute.
    • The target attribute cannot already be mapped to another attribute.
    • The source attribute must be visible on the form.
    • The target attribute must be a field that a user can enter data into.
    • If the attributes are picklists, the integer values for each option should be identical.
    • Address ID values cannot be mapped.

    Important

    If you want the owner of the new record to be the person who created it, don't map the owner field.

Save and publish

After you have configured the relationship and the relationship mappings:

  1. Click Save and Close to close the relationship form.
  2. On the Actions toolbar, click Publish.

Create a cloned record

Now that you have created the relationship and configured the relationship mappings, you can test creating a cloned record.

  1. Open an existing Lead record.
  2. Under Details, click the Cloned Leads associated view.
  3. In the toolbar, click New Lead.
  4. Confirm that the new lead form fields are populated with the desired data from the source record.

    Note

    Be sure to check all the tabs.

Related Links