RSS

How to Create Records through Dialog Process and do fields mapping with the Parent Record

06 Jan

Introduction

As we know, in MS CRM, we always try to find solution of any requirement through Out Of The Box. It doesn’t mean that, we can’t do it by writing code. But Out of The Box gives better performance. So, let’s discuss how to create records through Dialog Process and do fields mapping with the Parent Record.

Background

According to one of my project requirement, we had to create new record(s) on custom button click, from one existing record and that will be done only through Dialog Process. Before record create, in background, some of data from parent record should automatically get populated to new record’s fields (i.e. Fields mapping). I have found a solution by doing some research.

Steps

Let’s explore step by step.

Here I will open Dialog Process from existing Contact record and create Contact and Opportunity records through dialog sequentially.

Step 1: Create a Process of Dialog Category

Create Dialog Process

Step 2: Add a step of “Page” and under which add “Prompt and Response” step, then click “Set properties” to to create control for record inside dialog

See the following picture.
Add Step Page

Step 3: Mapping Dialog Fields with Contact Fields

After creating all fields required, add a step of “Create record” from Add Steps DropDown. Then choose the record type and click “Set Properties“. Here we will be able to do fields mapping using both Parent data and Dialog Fields data.
The Red colored box on the right side is showing all fields contains in Dialog. Map those fields with corresponding fields in Contact.
Mapping Dialog Fields with Contact Fields

Step 4: Populating Parent Fields data to New Record

The Red Colored box showing fields mapping between Parent record and New record. Same way choose any field and map that with field of Contact
Populating Parent Fields data to new record

Step 5: To set Parent record with one Lookup field of new record

Follow the below Picture.
Set Parent record with Lookup field of new record

Step 6: To add a created record’s link in the end of Dialog

Add a new page and again add a step of “Prompt and Response” under it. Then click Set properties and follow the below image. After that activate the Dialog Process.
Add created record link in the end of Dialog

Step 7: Script to open created Dialog on Button Click

  • Copy the Id of the new Dialog Process from location bar and then do the following
  • Create a Web Resource of Script type using below script
  • Add the Web Resource to the Button Click Event
function LaunchModalDialog()
{
    var dialogId = "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"; //id of dialog process
    var recordId = Xrm.Page.data.entity.getId();
    var typeName = Xrm.Page.data.entity.getEntityName();
    recordId = recordId.toString();
    recordId = recordId.replace("{", "");
    recordId = recordId.replace("}", "");

    var serverUrl = Xrm.page.getServerUrl();
    
    // Load modal
    var serverUri = serverUrl +'/cs/dialog/rundialog.aspx';

    var mypath = serverUri +'?DialogId=%7b' + dialogId.toUpperCase() +'%7d&EntityName=' + typeName + '&ObjectId=%7b' + recordId +'%7d';

    // First item from selected contacts only
    window.showModalDialog(mypath);

    // Reload form.
    window.location.reload(true);
}

By Sukanta Mangal
Software Engineer @Team DynamicsCRM.
Mindfire Solutions

Advertisements
 
 

Tags: , , , , , , , , , , , , , , , ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: