Welcome to MSDN Blogs Sign in | Join | Help

The Pesky Name Field on Custom Entities

When you create a new custom entity by default, it creates a field called Name that is used on lookups, etc. If you don't use the field, it can cause some headaches.  I have been using this as an area to store some information that would make searching on it much easier and automatically fill in the field. (So I don't have to type any more than necessary.)

Shad from Illinois who is a customer who contacted my about some other issues and after pointing him in the right direction for this, he shared back his code for us. :-) Thanks Shad! So in his case he has both the contact and the account linked to the custom entity.  In the OnSave area he put this code. You could put it in On Save or OnLoad or an OnChange.

var lookupItem = new Array;

var contactName = new Array;

// This will get the lookup for the attribute primarycontactid on the Account form.

lookupItem = crmForm.all.new_companynameid.DataValue;

contactName = crmForm.all.new_contactnameid.DataValue;

// If there is data in the field, show it in a series of alerts.

if (lookupItem != null)

{

   // The text value of the lookup.

   crmForm.all.new_name.DataValue = lookupItem[0].name + " - " + contactName[0].name;

crmForm.all.new_name.ForceSubmit = true;

}

else

{

crmForm.all.new_name.DataValue = contactName[0].name;

crmForm.all.new_name.ForceSubmit = true;

}

Published Friday, May 09, 2008 3:42 PM by Ben Vollmer

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# re: The Pesky Name Field on Custom Entities

Just an FYI.  Because it's client side scripting, you can't be assured that the name field will be updated by bulk edits, workflow updates, plugin updates, etc...  It will only take place when a manual entry is made on the form.

Sunday, May 11, 2008 9:39 PM by Jon G

# re: The Pesky Name Field on Custom Entities

We do this in precreate and preupdate callouts (3.0) and plugins (4.0) to account for the scenario Jon G points out above. We've toyed with the idea of doing as workflows in 4.0 to make it more transparent to the client, but we're afraid of the overhead.

Tuesday, May 13, 2008 2:03 PM by Chris

# Pesky Name Field - Part Deux

This is an alternative method of doing the same thing we talked about with this post.   John G from

Friday, May 16, 2008 4:25 PM by East Region Microsoft CRM

Leave a Comment

(required) 
required 
(required) 
 
Page view tracker