Friday, March 26, 2010

Populate CRM Fields from Parent Window

There are a number of people who have posted about copying a record via JScript button in CRM, and this post isn't far off from that concept. My coworker found a great way to implement the concept of opening a record and populating fields on the newly opened window, based on data from the originating window. And that is quickly opening an activity.

This customization cuts down the number of clicks to open a new Activity from 4, down to 1. 4 being click on the record you wish to create an activity for, click "Activities", click "New", click the activity type, click Ok. You can double click on the activity type to open it, but that's still 4 clicks technically. With this customization, users just click the button of the activity type. Done.

In a piece of software where users already feel like there are a lot of clicks and windows, this helps significantly.

Ok, now the good part. How do we do it?

Add a button to the entity you want to apply this customization to within the ISV.config file (in this example I use the contact):

<Entity name="contact" >
<ToolBar ValidForCreate="0" ValidForUpdate="1">
<Button Icon="/_imgs/ico_16_142.gif"
JavaScript="window.open('http://crmserver/CompanyName/activities/appointment/edit.aspx?');" PassParams="1"
WinParams="" WinMode="0">
<Titles>
<Title LCID="1033" Text="New Activity" />
</Titles>
<ToolTips>
<ToolTip LCID="1033" Text="Create new appointment activity" />
</ToolTips>
</Button>
</ToolBar>
</Entity>

Now, on the OnLoad script of the given activity (in this case the Appointment), add the following code:

//appointment onload script
if (window.opener.crmForm) {
var rgid = window.opener.crmForm.ObjectId;
var rgtype = window.opener.crmForm.ObjectTypeCode;
}
if (rgtype == 1) {
var rgname = window.opener.crmForm.all.name.DataValue;
}
if (rgtype == 2) {
var rgname = window.opener.crmForm.all.fullname.DataValue;
}

if (rgid != null) {
var oItems = new Array();
oItems[0] = new LookupControlItem(rgid, rgtype, rgname);

crmForm.all.regardingobjectid.DataValue = oItems;
}


Done. Not too difficult and end users will love it.

David Fronk
Dynamic Methods Inc.

1 comment:

Owen said...

great post Fronk! found this just searching google, lol.

Post a Comment

Post a Comment